473,396 Members | 1,804 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

question about select tag in php

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"></optionthere 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 <optiontag 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.
Mar 31 '08 #1
2 1709
Use the HTML tag <optgroup label="Region X"to seperate both sets in a
single select, and you'll be happy with no PHP coding.

Regards,
--
Guillaume
Mar 31 '08 #2
Sudhakar wrote:
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"></optionthere 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 <optiontag 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.
I don't think I'd have both the city and the region in the same select
box. Have one for the city, then another for the region in the city.
Use Javascript or Ajax to populate the Region box based on the City
selected.
--
==================
Remove the "x" from my email address
Jerry Stuckle
JDS Computer Training Corp.
js*******@attglobal.net
==================

Mar 31 '08 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

11
by: Markus Breuer | last post by:
I have a question about oracle commit and transactions. Following scenario: Process A performs a single sql-INSERT into a table and commits the transaction. Then he informs process B (ipc) to...
3
by: ricksql | last post by:
#temptable got order,fname and age. trying to find two high maxes per each order. query returns (1) but (2) is correct answer. supposedly, max(age2) < max(age1). **** select d.order,case d.t...
1
by: Scott | last post by:
The following is the XML I have to work with. Below is the question <Table0> <CaseID>102114</CaseID> <CaseNumber>1</CaseNumber> <DateOpened>2005-06-14T07:26:00.0000000-05:00</DateOpened>...
5
by: Sue | last post by:
I wrote a script that uses the sp_refreshviews. The script will be part of a larger one that is automatically run in multiple databases where different views exist. Question: My understanding...
8
by: Együd Csaba | last post by:
Hi All, how can I improve the query performance in the following situation: I have a big (4.5+ million rows) table. One query takes approx. 9 sec to finish resulting ~10000 rows. But if I run...
3
by: Tcs | last post by:
My backend is DB2 on our AS/400. While I do HAVE DB2 PE for my PC, I haven't loaded it yet. I'm still using MS Access. And no, I don't believe this is an Access question. (But who knows? I...
2
by: Eitan | last post by:
Hello, I want a solutions for a compicateds sql select statments. The selects can use anything : views, stored procedures, analytic functions, etc... (not use materialized view, unless it is...
10
by: Robert | last post by:
I am an attorney in a non-profit organization and a self-taught programmer. I'm trying to create a client db that will allow me to search for potential conflicts of interest based either on Social...
5
by: wugon.net | last post by:
question: db2 LUW V8 UNION ALL with table function month() have bad query performance Env: db2 LUW V8 + FP14 Problem : We have history data from 2005/01/01 ~ 2007/05/xx in single big...
25
by: bonneylake | last post by:
Hey Everyone, Well i am not sure if my question needs to be here or in coldfusion. If i have my question is in the wrong section i am sorry in advance an will move it to the correct section. ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.