Jump to content

HOW TO SHOW OTHER DATA WHEN A COUNTRY NAME IS SELECTED FROM A LIST BOX


rumon007

Recommended Posts

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!!!

 

 

     

 

 

 

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

<?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>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.