Jump to content

[SOLVED] How to define a variable in a selectbox


patheticsam

Recommended Posts

Hi Guys! I'm just having a little problem..I made a multiple selectbox with some data stored in mySQL database. I just want to be able to define a variable depending what I select in that selectbox without having to process it through a form. As soon as I click on a choice the variable is defined. Is anyone can help me out?

 

Here's the code :

 

<select name="client" size=5 multiple length=30>

<?php

 

$db = mysql_connect('localhost', 'username', 'password');

 

mysql_select_db('database',$db);

 

$sql = "SELECT `field1`, `field2`, `field3` FROM table";

 

$rs = mysql_query($sql);

 

while($row = mysql_fetch_array($rs))

{

  echo "<option value=\"".$row['field3']."\">".$row['field1']." ".$row['field2']."\n  "; <-----I want to define the variable depending on the choice I make here!

}

?>

 

</select>

 

Thanks in advance for your help!!

 

I think its more Javascript oriented thing. One straight forward thing is you can use OnChange command on that select box and each time you select anything, send that value with GET method, and hence set the php variable from the GET variable. The only problem is the whole page will be reloaded each time. One better procedure is to store that value in a hidden field for later use. But if you want to execute some php command with the new selected item each time user select a new thing, I guess the only possible way is the one I mentioned first. Because, you can't set php variable from javascript.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.