| | |
Help with Drop down list
Please support our JavaScript / DHTML / AJAX advertiser: PostgreSQL or MySQL? Compare and contrast the two most popular open source databases
![]() |
•
•
Join Date: Jan 2008
Posts: 16
Reputation:
Solved Threads: 0
I want to change this code so that you can enter "Fruits" in a textr field and the drop down is populated instead of selecting "Fruits" from a drop down.
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
<!doctype html public "-//w3c//dtd html 3.2//en"> <html> <head> <title>Multiple drop down list box from plus2net</title> <SCRIPT language=JavaScript> function reload(form) { var val=form.cat.options[form.cat.options.selectedIndex].value; self.location='dd.php?cat=' + val ; } </script> </head> <body> <? /* If register_global is off in your server then after reloading of the page to get the value of cat from query string we have to take special care. To read more on register_global visit. http://www.plus2net.com/php_tutorial/register-globals.php */ @$cat=$_GET['cat']; // Use this line or below line if register_global is off //@$cat=$HTTP_GET_VARS['cat']; // Use this line or above line if register_global is off ///////// Getting the data from Mysql table for first list box////////// $quer2=mysql_query("SELECT DISTINCT category,cat_id FROM category order by category"); ///////////// End of query for first list box//////////// /////// for second drop down list we will check if category is selected else we will display all the subcategory///// if(isset($cat) and strlen($cat) > 0){ $quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory where cat_id=$cat order by subcategory"); }else{$quer=mysql_query("SELECT DISTINCT subcategory FROM subcategory order by subcategory"); } ////////// end of query for second subcategory drop down list box /////////////////////////// echo "<form method=post name=f1 action='dd-check.php'>"; /// Add your form processing page address to action in above line. Example action=dd-check.php//// ////////// Starting of first drop downlist ///////// echo "<select name='cat' onchange=\"reload(this.form)\"><option value=''>Select one</option>"; while($noticia2 = mysql_fetch_array($quer2)) { if($noticia2['cat_id']==@$cat){echo "<option selected value='$noticia2[cat_id]'>$noticia2[category]</option>"."<BR>";} else{echo "<option value='$noticia2[cat_id]'>$noticia2[category]</option>";} } echo "</select>"; ////////////////// This will end the first drop down list /////////// ////////// Starting of second drop downlist ///////// echo "<select name='subcat'><option value=''>Select one</option>"; while($noticia = mysql_fetch_array($quer)) { echo "<option value='$noticia[subcategory]'>$noticia[subcategory]</option>"; } echo "</select>"; ////////////////// This will end the second drop down list /////////// //// Add your other form fields as needed here///// echo "<input type=submit value=Submit>"; echo "</form>"; ?> <center><a href='http://www.plus2net.com'>PHP SQL HTML free tutorials and scripts</a></center> </body> </html>
its so easy
Help as an alias
I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
I think programming is great................
Tour Travel weblink by me and about Tour ,
Go To My Home Page and I m in Webdevelopment.
•
•
Join Date: Jan 2008
Posts: 16
Reputation:
Solved Threads: 0
Please help me then!!!
I want to eneter "Fruits" into a text field and then for the Fruit options to populate the 2nd drop down menu.
So all i want to do is replace the 1st drop down menu with a text field where i can manually enter a category.
Thankyou!!
I want to eneter "Fruits" into a text field and then for the Fruit options to populate the 2nd drop down menu.
So all i want to do is replace the 1st drop down menu with a text field where i can manually enter a category.
Thankyou!!
•
•
Join Date: Aug 2008
Posts: 381
Reputation:
Solved Threads: 33
Hi,
The challenge with what you are asking is that you must rely on what the user enters into the text field and that data must match exactly what the search term is from the database record ... does that make sense?
So if someone enters Fruit, friut, fruits in the text field, none of them will match up correctly with fruit which is the matching field to populate your subcategory list.
You can try to manage some of this concern using javascript validation and post-processing ...
This will remedy cases like Fruit and fruits but not transposed letters or miss spellings like friut or frute ... which are both actually quite common problems.
From here you will need to populate the form variable to be submitted with the identified 'cat' value and then activate or submit the form with javascript -- which means all of this must be processed before the form is submitted with the existing script on your page.
I'm not really willing to sit here and rewrite this entire page to allow text field entry of options, but if you decide to take this on, I will be glad to give you pointers along the way.
Good luck
The challenge with what you are asking is that you must rely on what the user enters into the text field and that data must match exactly what the search term is from the database record ... does that make sense?
So if someone enters Fruit, friut, fruits in the text field, none of them will match up correctly with fruit which is the matching field to populate your subcategory list.
You can try to manage some of this concern using javascript validation and post-processing ...
JavaScript / DHTML / AJAX Syntax (Toggle Plain Text)
var cat = document.getElementById('cat').value; if ( /fruit/i.test( cat ) ) { cat = 'fruit'; }
From here you will need to populate the form variable to be submitted with the identified 'cat' value and then activate or submit the form with javascript -- which means all of this must be processed before the form is submitted with the existing script on your page.
I'm not really willing to sit here and rewrite this entire page to allow text field entry of options, but if you decide to take this on, I will be glad to give you pointers along the way.
Good luck
![]() |
Similar Threads
- php mysql drop down list (PHP)
- drop down list question. (ASP.NET)
- Populate One Drop Down List From Another (ASP.NET)
- Populating a Drop-down List (PHP)
- view employee info for the employee selected from the drop down list (PHP)
- Data Binding to a Drop Down List? (ASP.NET)
- Passing a drop down list item's value (HTML and CSS)
- Blank drop list (PHP)
Other Threads in the JavaScript / DHTML / AJAX Forum
- Previous Thread: suggest a tool to make javascript unreadable
- Next Thread: problem with date validation
| Thread Tools | Search this Thread |
Tag cloud for JavaScript / DHTML / AJAX
ajax ajaxexample ajaxjspservlets array autoplay blackjack browser captchaformproblem checkbox child class close codes date debugger dependent developer disablefirebug dom editor element embed engine events explorer ext file firefox flash form forms game gears getselection google gxt hiddenvalue highlightedword hint html ie7 ie8 iframe internet java javascript javascripthelp2020 jquery jsf jsfile jsp jump libcurl maps marquee masterpage math matrixcaptcha media mysql object onerror onmouseoutdivproblem onreadystatechange parent passing paypal pdf php player position post programming rated redirect runtime safari scriptlets scroll search security session shopping size software solutions star stars stretch synchronous toggle tweet unicode variables web webkit webservice window wysiwyg \n





