pakenney38 Posted December 14, 2007 Share Posted December 14, 2007 I know this is probably some AJAX based thing I want to do, but I want to make a second form element appear on a page based on the action of a first form element. The second element may or may not contain dynamic content. For example: I click on a radio button and a drop-down list appears filled with names that have been populated from a MySQL table. Does anyone have any good documentation or examples they could point me towards on how to do this? Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 14, 2007 Share Posted December 14, 2007 what about this (im not doing the whole thing for you but this will help alot) <html> <input type="radio" name="yes" onchange=" if(this.value=='yes'){ document.getElementById('dropDown').style.display=''; }else{ document.getElementById('dropDown').style.display=none''; }"> <div id="dropDown" style='display:none;'> What ever you want to show up here... </div> </html> Quote Link to comment Share on other sites More sharing options...
ccrevcypsys Posted December 14, 2007 Share Posted December 14, 2007 will this help? Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted December 14, 2007 Author Share Posted December 14, 2007 How would I do this if there is more than one radio button? could I just put in a javascript function and make calls to it on each radio button in the group rather than put the code in for each button? Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted December 14, 2007 Author Share Posted December 14, 2007 I'm not sure what I am supposed to do with this code, but it doesn't appear to work as it is. Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted December 14, 2007 Author Share Posted December 14, 2007 Yeah this doesn't appear to do anything even if I put it into a function. Quote Link to comment Share on other sites More sharing options...
lemmin Posted December 14, 2007 Share Posted December 14, 2007 It is simple javascript, like ccrevcypsys suggested, if the second element is not dynamic. All you have to do is make it visible. Here is a simple drop down box that will show a new dropdown box once a user has selected something. <select name="s1" onChange="s2.style.visibility='visible'"> <option name="NULL">Select a value</option> <option name="1">1</option> </select> <br> <select name="s2" STYLE="visibility:hidden"> <option name="NULL">Select a value</option> <option name="1">1</option> </select> However, if you want the second box to have content that is dynamically generated, you will need a separate php file. To do this without changing the location of the page, you can use an iframe that is exactly the size of the form element in it. It will look like it is on the current page, but it is actually a different one. Then, using the same kind of javascript, instead of making it visible, you change the location of the page to a php file that takes the input of the first element and generates the content from it. Good luck! Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted December 14, 2007 Author Share Posted December 14, 2007 Thanks for the information! Quote Link to comment Share on other sites More sharing options...
pakenney38 Posted December 14, 2007 Author Share Posted December 14, 2007 Looking now at what this does, it's cool, but not useful. It needs to be able to produce a different menu depending on the option chosen of the first menu. It also needs to make the second menu go away if the first menu option has no corresponding selections to make in a second menu. Quote Link to comment Share on other sites More sharing options...
corbin Posted December 14, 2007 Share Posted December 14, 2007 This is an example of a text box that drops down autocompletion suggestions based on typed text.... You could probably mod it if you're decent with HTML/JS to use radio buttons and then make a select box or something. http://members.aol.com/barryaandrew/xmlhttp/article.html (from Barand's sig) Also, you can probably just google around, learn some about AJAX, find or write some JS to edit the HTML stuff, and then go for it. Quote Link to comment 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.