Results 1 to 8 of 8
-
12-20-2004, 11:32 AM #1Web Hosting Master
- Join Date
- Jun 2004
- Posts
- 890
Help populating 2 drop down lists from db
Hi I need to make a form to submit some values to a db,
the form will have 2 drop down lists,
both will load from mysql
list 1 will be loaded on page load so thats ok
but list 2 needs to be loaded depending on the option selected in list1 .
can you please help me with that?
-
12-20-2004, 01:39 PM #2Junior Guru
- Join Date
- May 2003
- Location
- Halifax, Nova Scotia, Canada
- Posts
- 200
To do this with both drop downs on the same page you will need to populate Javascript arrays on the page load, it is much easier to do this on two separate pages if you can, if not though, it is possible, however if you have a large set of data to possibly populate the forms it will increase the loading times since all of the data will be printed inside the javascript that is sent out to the web browser.
Matt
-
12-20-2004, 02:34 PM #3Web Hosting Master
- Join Date
- Mar 2004
- Location
- Los Angeles
- Posts
- 622
Code:<? $query = mysql_query("SELECT field FROM table WHERE anything='$given'"); $result = mysql_fetch_array($query); ?> <input type="select" name="menu"> <option><?php echo $result[0]; ?></option> <option><?php echo $result[1]; ?></option> <option><?php echo $result[2]; ?></option> . .
-
12-20-2004, 03:09 PM #4WHT Addict
- Join Date
- Nov 2003
- Location
- Netherlands
- Posts
- 164
A way to do this is to post the $value of the first combobox to itself (for example page.php?selection=bla).
On the page (re)load, check if the $seletion value exist, then execute a second query to fill a second combobox.
Then fcarsenal's code would look something like this..
<FORM name='selectionform'>
<SELECT name='subselection' onChange='window.location=document.selectionform.subselection.options[document.selectionform.subselection.selectedIndex].value'>
<OPTION SELECTED value='javascript:void(0)'>--Choose--
<OPTION value='page.php?selection=$result[0]'>$result[0]</OPTION>
<OPTION value='page.php?selection=$result[1]'>$result[1]</OPTION>
<OPTION value='page.php?selection=$result[2]'>$result[2]</OPTION>
</SELECT >
</FORM >Last edited by Vult-r; 12-20-2004 at 03:12 PM.
-
12-20-2004, 05:02 PM #5Web Hosting Master
- Join Date
- Jun 2004
- Posts
- 890
^ thanks guys for your response, but i've realised that this way will be too complicated for what i need it for, so instead, i'll be displaying a dynamic link on each page of the site (web directory)
the link will have right catagory and subcat within it, so the processor file will just display the names for the catagy the user is about to submit to. .
my question now is,
my site will be only one page(static) every other page will be dynamic.
i'm using something like this
www.mysite.com.com/index.php?catid=4&subid=22
in the php file i have this code
i know my synax is wrong here , i'm just typing rough
if isset(catid) && isset(subid)
{
echo 'the code for my form';
}
form action will be the same file
the question i have is how do i process the form inthis file and how would i display the confirmation on successful submition?
i don't want to use another page coz that will make it harder to manage stuff in the long run.
-
12-20-2004, 05:25 PM #6Web Hosting Master
- Join Date
- Jun 2004
- Posts
- 890
I'm actually working on it so i might sort it out, but in case someone replies thought i'll also mention that all the form validation will be done using javascript so alll i want from the php bit is to
1 display the form
2 on submit send the data and show the user a thankyou message.
-
12-20-2004, 06:07 PM #7WHT Addict
- Join Date
- Dec 2004
- Location
- Akron, Ohio
- Posts
- 115
A quick note: I wouldn't rely exclusively on JavaScript to do your form validation. Some very nasty things (read: SQL Injections) are trivial to do when this is your only form of validation.
-
12-21-2004, 10:11 AM #8Web Hosting Master
- Join Date
- Jun 2004
- Posts
- 890
hi thanks i've heard about addslashes but i don't know what to do with them. can you help?