This topic is locked
[SOLVED]

 Get value from <select>

5/16/2010 11:13:52 PM
PHPRunner General questions
M
mid3vil author

How do you get the value of selected item in a custom dropdown list?

I want to select the item, then when a button is clicked return the value of the drop down
I create the dropdown from the following code
=============================================

$str = "";
//select values from database

$str.= "<select name=\"JobDropDown\"><option value=\"Please Select\">";

global $conn;

$strSQL = "select Job_Name, CompanyID from Jobs";

$rs = db_query($strSQL,$conn);
while ($data = db_fetch_array($rs)){

if ($data["CompanyID"] == $_SESSION["_Contractor_Jobs_OwnerID"]){

$str.="<option value=\"".$data["Job_Name"]."\">".$data["Job_Name"]."</option>";

}//end if ($data ["CompanyID"] yadda yadda

}//end while ($data =db_fetch_array($rs))

$str.="</select>";

echo $str;
=============================================
I tried inserting a button, and do a simple $result["txt"] = ... but dunno what to set it equal to
Thanks

M
mid3vil author 5/17/2010



How do you get the value of selected item in a custom dropdown list?

I want to select the item, then when a button is clicked return the value of the drop down
I create the dropdown from the following code
=============================================

$str = "";
//select values from database

$str.= "<select name=\"JobDropDown\"><option value=\"Please Select\">";

global $conn;

$strSQL = "select Job_Name, CompanyID from Jobs";

$rs = db_query($strSQL,$conn);
while ($data = db_fetch_array($rs)){

if ($data["CompanyID"] == $_SESSION["_Contractor_Jobs_OwnerID"]){

$str.="<option value=\"".$data["Job_Name"]."\">".$data["Job_Name"]."</option>";

}//end if ($data ["CompanyID"] yadda yadda

}//end while ($data =db_fetch_array($rs))

$str.="</select>";

echo $str;
=============================================
I tried inserting a button, and do a simple $result["txt"] = ... but dunno what to set it equal to
Thanks


For Clarification, I am adding a dropdown list to the record_controls{$id} section in my _list.php file.

My goal is this,
Lets say I have a user_list.php showing my users, and my created dropdown is my current jobs available.
I want to be able to put a check into the check box beside some users, then select a job from my dropdown and click a button to offer these people a job(Insert a new record into another table for each user checked)

A
ann 5/18/2010

Hi,
to save the value of the dropdown make the following change in your code(bold):

$str.= "<select name=\"JobDropDown\" id=\"JobDropDown\"><option value=\"Please Select\">";



Then you can use

document.getElementById('JobDropDown').value

to return value selected in this dropdown

M
mid3vil author 5/19/2010



Hi,
to save the value of the dropdown make the following change in your code(bold):
Then you can use

document.getElementById('JobDropDown').value

to return value selected in this dropdown


Thanks, worked like a charm.