This topic is locked
[SOLVED]

 Get Value From Dropbox Snippet

1/18/2013 10:01:33 AM
PHPRunner General questions
S
sickacid author

Hi I've done this lookup in a snippet and it works, but i need to know in a global var what is the id of selected row, to do something else with a botton, what can i do?
global $conn;
$str = "";

$str.= "<select onselect=\"window.location.href=this.options[this."."selectedIndex].value;\"><option value=\"\">Seleziona un giro</option>";
//select values from database

$strSQL = "select concat(IdConsegna,' - ',Giro,' - ',DataConsegna) as IdConsegna from vista_tabellaconsegne";

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

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

$str.="</select>";

echo $str;

C
cgphp 1/18/2013

In the "Client before" event of the button you can get the value of the dropdown as follows:
http://stackoverflow.com/questions/2780566/to-get-selected-value-of-a-dropdown-select-element-in-jquery

S
sickacid author 1/21/2013

The snippet is named: vista_tabellabolle_snippet

and in the drop down list i get a result of concat mysql query, something like this:
--ID------DAY----DATE

3213123 - MON - 31/03/2012

3213124 - MON - 31/03/2012

3213125 - TUE - 31/03/2012

etc...
in the client before i've added this code but won't works:
var value = $('#vista_tabellabolle_snippet:selected').text();

alert (value);
the result is nothing in the alert box.

C
cgphp 1/21/2013

Simone, the selector is wrong. You have to get the id of the dropdown not the php snippet name. Check this jquery crash course: http://www.1stwebdesigner.com/tutorials/jquery-beginners-1/

S
sickacid author 1/21/2013



Simone, the selector is wrong. You have to get the id of the dropdown not the php snippet name. Check this jquery crash course: http://www.1stwebdesigner.com/tutorials/jquery-beginners-1/


But the dropdown is generated by snippet, where can i get the id name of this dropdown?

C
cgphp 1/21/2013

Check the following code:
global $conn;

$str = "";

$str.= "<select .value;\"><option value=\"\">Seleziona un giro</option>";

//select values from database

$strSQL = "select concat(IdConsegna,' - ',Giro,' - ',DataConsegna) as IdConsegna from vista_tabellaconsegne";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

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

$str.="</select>";

echo $str;
var value = $('#[color="#FF0000"][b]my_dropdown_id
:selected').text();

alert (value);

S
sickacid author 1/21/2013

This is my working solution:
add snippet for create dropdown:

global $conn;

$str = "";

$str.= "<select name=\"JobDropDown\" id=\"JobDropDown\"><option value=\"\">Seleziona un giro</option>";
//select values from database

$strSQL = "select IdConsegna, concat(IdConsegna,' - ',Dataconsegna,' - ', Ciclo,' - ',Giro) as Giro from vista_tabellaconsegne";

$rs = db_query($strSQL,$conn);

while ($data = db_fetch_array($rs))

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

$str.="</select>";

echo $str;


in the button (client before)

var value = document.getElementById('JobDropDown').value;

alert (value);