473,396 Members | 1,714 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= [php]
<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>
[/php]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 [php]
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}[/php]
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[php]
<option <?php if ($northisland=="0"){echo "SELECTED";}?> value="0"></option>
<option <?php if ($northisland=="1"){echo "SELECTED";}?> value="1"></option>[/php]2.
how can i get around the conflict that is being created by introducing this value=0 with [php]
if(!($city1 == "region1") && !($city2 == "region2"))
{
$error.="Please select only 1 Region<br />";
}[/php]
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 1143
dlite922
1,584 Expert 1GB
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.
DUDE, i'm so confused with your little rule numbering scheme you got going on, where's Appendix B? (joke)

Please explain in plain words, you've proven enough to us that you've attempted at some code, we agree to help you, here's what i think you want:

User can select from 2 drop downs (cities, regions, whatever), and they can only choose one of the two, not both.

What other conditions do you have on these two fields?

Let us know,

thanks,


DM
Mar 31 '08 #2
ronverdonk
4,258 Expert 4TB
I did the code tagging for you this time, but next time please enclose your posted code in [code] tags (See How to Ask a Question).

This makes it easier for our Experts to read and understand it. Failing to do so creates extra work for the moderators, thus wasting resources, otherwise available to answer the members' questions.

Please use [code] tags in future.

MODERATOR
Mar 31 '08 #3

Sign in to post your reply or Sign up for a free account.

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: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

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.