rumon007 Posted January 27, 2009 Share Posted January 27, 2009 I have a list box named select_country showing a list of countries. All the country names come from a mysql database table named call_rate. I also created a text field and a button in my form. I have written the following code to show all country names in the list box: CODE: <table width=50% hight=90% cellpadding=10 cellspacing=0 border=1 align=center> <tr> <td> <select name=\"select_country\">"; while($country_result= mysql_fetch_array($get_country_result)) { $country_id=$country_result[id]; $country_name=$country_result[country_name]; $call_rate=$country_result[rate]; $display_block.="<option value=\"$country_id\">$country_name</option>"; } $display_block.= "</select></td>"; $display_block.= " <td><input type = \"text\" name=\"edit_rate\" size=10></td> <td><input type = \"submit\" name = \"submit\" value=\"Update\"></td> <input type = \"hidden\" name = \"op\" value = \"edit\"> </tr> </table>"; And finally I printed the $display_block string. What I am trying to do is whenever I will select a country name from the list the associated call rate will be displayed in the text field. (‘rate’- field name in database). And when after any change in rate when I will click the button the new rate will replace the old rate in the database. Please help me in writing the code for doing this!!! Quote Link to comment Share on other sites More sharing options...
bluesoul Posted January 27, 2009 Share Posted January 27, 2009 It sounds like you're going to need to select all the rates along with the country codes and use JavaScript to populate the text field with the correct data. JavaScript ain't my thing so maybe someone else on here can get you going but it doesn't sound terribly difficult. Quote Link to comment Share on other sites More sharing options...
Psycho Posted January 27, 2009 Share Posted January 27, 2009 <?php $display_block = "<table width=\"50%\" hight=\"90%\" cellpadding=\"10\" cellspacing=\"0\" border=\"1\" align=\"center\">"; $display_block .= "<tr>\n"; $display_block .= "<td>\n"; $display_block .= "<input type=\"hidden\" name=\"op\" value=\"edit\">\n"; $display_block .= "<select name=\"select_country\">\n"; while($country= mysql_fetch_array($get_country_result)) { $js_array .= "rates[{$country['id']}] = '{$country['rate']}';\n"; $display_block.="<option value=\"{$country['id']}\">{$country['country_name']}</option>\n"; } $display_block .= "</select></td>\n"; $display_block .= "<td><input type=\"text\" name=\"edit_rate\" size=\"10\"></td>\n"; $display_block .= "<td><input type=\"submit\" name=\"submit\" value=\"Update\"></td>\n"; $display_block .= "</tr>\n"; $display_block .= "</table>\n"; ?> <html> <head> <script type="text/javascript"> rates = new Array(); <?php echo $js_array; ?> function displayRate(selObj) { selID = selObj.options[selObj.selectedIndex].value; document.getElementById('edit_rate').value = rates[selID]; } </script> </head> <body> <?php echo $display_block; ?> <body> </html> 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.