meman1188 Posted July 2, 2006 Share Posted July 2, 2006 I'm creating a form with html and the values for my drop down menus come from mysql tables. Got the first one working great, but i need the 2nd one to dynamically update based on the selection of the first (from what i know .. using onChange). When the 2nd one is updated it needs to call mysql again (accessing a different table if that matters) to get its drop down options based on the value of what was selected in the first.. Only way i know how to do this is javascript and since it doesn't support mysql, my knowledge is very limited on this topic. Any help is greatly appreciated and if anything didn't make sense please just let me know.-- Brady Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/ Share on other sites More sharing options...
Barand Posted July 2, 2006 Share Posted July 2, 2006 Have a look at [url=http://members.aol.com/barryaandrew/xmlhttp/article.html]AJAX article[/url] Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52158 Share on other sites More sharing options...
fenway Posted July 3, 2006 Share Posted July 3, 2006 Depending on the size of each dropdown, you might be able to retrieve both lists at runtime (e.g. province/country lists); alternatively, IFRAMEs work wonders. Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52332 Share on other sites More sharing options...
mwq27 Posted July 3, 2006 Share Posted July 3, 2006 I am trying to do pretty much the same thing. I want to have a drop down list with names from a table, and when the user clicks on a name, the ID number associated with that name will appear in a textbox next to the drop down list. Can someone help me with this? thanks Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52480 Share on other sites More sharing options...
fenway Posted July 3, 2006 Share Posted July 3, 2006 Well, if you're already pulling all the names, it's the same amount of work to pull the IDs as well, so there's no need for another round-trip to the server. Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52488 Share on other sites More sharing options...
mwq27 Posted July 3, 2006 Share Posted July 3, 2006 Ok, i got the id's, now how do I make it so when i click on the name, the ID will appear in the text box? Will I have to do javascript or something? Thanks Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52489 Share on other sites More sharing options...
Barand Posted July 3, 2006 Share Posted July 3, 2006 This will do it[code]<html><head><meta name="generator" content="PhpED Version 4.5 (Build 4513)"><SCRIPT language="javascript"> function setID (id, textid) { document.getElementById(textid).value = id; }</SCRIPT></head><body><form><select name="user" onchange='setID(this.value,"userid")'> <option value=''>- select user -</option> <option value="1">User 1</option> <option value="2">User 2</option> <option value="3">User 3</option></select><input type="text" name="id" id="userid" size="5"><input type="submit" name="submit" value="Submit"></form></body></html>[/code]But it does raise the question "Why do you want to put the id in a text box?"You should not br editing/changing id values. Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52604 Share on other sites More sharing options...
mwq27 Posted July 3, 2006 Share Posted July 3, 2006 Thanks for the reply, but I still need to be able to have the values of the drop down list to be the data from the MySQL database. I know I need a query to select the name and the ID from the table, then I need to have a drop down list with the names and a text box (uneditable) for the id's to be displayed. I think I will still need a javascript function, but I dont know how to create it. Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52655 Share on other sites More sharing options...
fenway Posted July 3, 2006 Share Posted July 3, 2006 This is no longer really a MySQL question anymore, is it? Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52673 Share on other sites More sharing options...
Barand Posted July 3, 2006 Share Posted July 3, 2006 try[code]<html><head><meta name="generator" content="PhpED Version 4.5 (Build 4513)"><SCRIPT language="javascript"> function setID (id, textid) { document.getElementById(textid).value = id; }</SCRIPT></head><body><form><select name="user" onchange='setID(this.value,"userid")'> <option value=''>- select user -</option> <?php // connect to mysql server and select db here $sql = "SELECT id, name FROM mytablename ORDER BY name"; $res = mysql_query($sql) or die(mysql_error()); while (list($id, $name) = mysql_fetch_row($res)) { echo "<option value='$id'>$name</option>" ; } ?> </select><input type="text" name="id" id="userid" size="5" readonly><input type="submit" name="submit" value="Submit"></form></body></html>[/code] Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-52694 Share on other sites More sharing options...
meman1188 Posted July 5, 2006 Author Share Posted July 5, 2006 Found a great tutorial to do what i was looking for, maybe it will help someone else:http://www.plus2net.com/php_tutorial/php_drop_down_list.php Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-53167 Share on other sites More sharing options...
mwq27 Posted July 5, 2006 Share Posted July 5, 2006 Thanks for the help, I got it to work. Quote Link to comment https://forums.phpfreaks.com/topic/13420-dynamic-mysql-form/#findComment-53391 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.