adige72 Posted April 15, 2011 Share Posted April 15, 2011 Hi. I would like to automatically fill in the textbox labeled "Amount 2" after choosing the value of Amount without refreshing the page. I guess it requires javascript or AJAX but i don't know how to do it. Any help please? http://i55.tinypic.com/29crpdz.jpg $options_amount = array("0","1","2","3","4","5","6","7","8","9","10+"); $metabox = array(); $metabox[] = array( "name" => "amount", "label" => "Amount", "desc" => "Choose the amount.", "std" => "0", "type" => "select", "options" => $options_amount); $metabox[] = array( "name" => "amount2", "label" => "Amount 2", "desc" => "No need to enter it.", "std" => "", "type" => "text"); Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 15, 2011 Share Posted April 15, 2011 I guess it requires javascript or AJAX but i don't know how to do it. So, why post in the PHP forum? Moving to JS forum. Quote Link to comment Share on other sites More sharing options...
adige72 Posted April 15, 2011 Author Share Posted April 15, 2011 Ok. Sorry about that. Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 15, 2011 Share Posted April 15, 2011 OK, the code you posted doesn't show anything about how the user selects an amount or how you would determine the value to populate in the text field. Here is a quick example script <html> <head> <script type="text/JavaScript"> function updateField(fieldID, newValue) { var fieldObj = document.getElementById(fieldID); fieldObj.value = newValue; } </script> </head> <body> Amount: <select name="amount" id="amount" onchange="updateField('amount2', this.options[this.selectedIndex].value);"> <option value=""></option> <option value="0">0</option> <option value="1">1</option> <option value="2">2</option> <option value="3">3</option> <option value="4">4</option> <option value="5">5</option> </select> <br> Amount2: <input type="text" name="amount2" id="amount2" /> </body> </html> Quote Link to comment Share on other sites More sharing options...
adige72 Posted April 15, 2011 Author Share Posted April 15, 2011 So how can i embed this code in a php file? Quote Link to comment Share on other sites More sharing options...
Psycho Posted April 18, 2011 Share Posted April 18, 2011 So how can i embed this code in a php file? The same way you output anything to the browser with PHP, echo ,print, etc. I only provided some sample code because you failed to show any of the relevant code for me to provide a modification. 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.