Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

PHP Forum


You are currently viewing our PHP Forum as a guest. Please register to participate.
Login



Freelance Jobs

Reply
question about select tag in php
Old 03-31-2008, 03:49 AM question about select tag in php
Ultra Talker

Posts: 254
Trades: 0
i have two select tags as part of a registration form, city1 city2 where city1 has a list of regions and similar for city2

there are different regions for city1 and city2 so instead of all the regions appearing one after the other i would like to create a blank option followed by the next set of regions for formatting purpose only.

ex=
<select name="city1">
<option <?php if ($city1=="region1"){echo "SELECTED";}?> value="region1">Select region1</option>
<option <?php if ($city1=="nameofregion1"){echo "SELECTED";}?> value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($city1=="nameofregion2"){echo "SELECTED";}?> value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>
</select>


<select name="city2">
<option <?php if ($city2=="region2"){echo "SELECTED";}?> value="region2">Select region2</option>
<option <?php if ($city2=="nameofregion1"){echo "SELECTED";}?> value="nameofregion1">nameofregion1</option>
<option <?php if ($northisland=="2"){echo "SELECTED";}?> value="2"></option>
<option <?php if ($city2=="nameofregion2"){echo "SELECTED";}?> value="nameofregion2">nameofregion2</option>
<option <?php if ($northisland=="3"){echo "SELECTED";}?> value="3"></option>
</select>


from a php validation perspective if a user does not select any of the regions or both the regions i am displaying an error message asking them to either select 1 region from either city1 or city2

as of now there is a blank option being displayed which is working fine, i am having an issue with the php validation.

until i introduced value=0 my rules for validating the select tag were:

1. user cannot leave both the select tags with the default option which is "Select region1" & "Select region2"
2. user cannot select both the regions from city1 & city2 select tags

the code of 2. is
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}


now by introducing <option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option> there is a conflict with the above php validation code used in point 2.

1.
is it correct to use 1,2,3 as part of the following <option> tag or should i only use 0 everywhere
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>

2.
how can i get around the conflict that is being created by introducing this value=0 with
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}
as i need the above php code and i also need the blank space for formatting purpose

please advice.

thanks.
sudhakararaog is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 03-31-2008, 07:08 AM Re: question about select tag in php
vectorialpx's Avatar
Extreme Talker

Posts: 249
Name: octavian
Location: Bucharest
Trades: 0
so... I make it so

$northisland = 'reg2'; // just for test

$select = '<option name="reg"><select value="reg1">region 1</select>
<select value="reg2">region 2</select><select value="reg3">region 3</select>
<select value="reg4">region 4</select></option>';

$select = str_replace('value="'.$northisland.'"', 'value="'.$northisland.'" selected="selected"', $select);
print $select;
__________________
you can
Please login or register to view this content. Registration is FREE
vectorialpx is offline
Reply With Quote
View Public Profile Visit vectorialpx's homepage!
 
Reply     « Reply to question about select tag in php
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.10763 seconds with 12 queries