tdors Posted May 29, 2007 Share Posted May 29, 2007 Below is the code that I have. I'm not totally familiar with JavaScript, but I'm getting the AJAX portion to work correctly, but how do I send the value of the drop down item selected to the "AJAX Query"? After "state=changed" I want to add "&xsellid=<The Value ID of the Drop Down>" What is the javascript function for that? Here is the line specifying the Select Statement --> I have the "$toecho .= "\n<select size='1' name='".$selectname."' class='".$dropstyle."' onchange='javascript: MyAjaxRequest(\"ajmn\",\"/handle_xsmysqllook.php?state=changed\")'>\n";" Please let me know if you need to know anything else/I've left anything out. function xselldropchange($selectname, $valueselected, $dropstyle) # $selectname - Name of the drop down box/"<Select>" to use # $valueselected - If specified, which id of the value to display # $dropstyle - Style of Dropdown box # # $toecho - HTML Code to Echo Back # $detailquery - Query to get information # # { $toecho = NULL; # Determine what the mysql query should be $dropquery = "SELECT incentive_id, incentive_name FROM incentive_list ORDER BY incentive_sort"; if ($dropquery <> NULL) { $dropresult = @mysql_query ($dropquery); // Run the query if ($dropresult) { // If this query ran okay $toecho .= "\n<select size='1' name='".$selectname."' class='".$dropstyle."' onchange='javascript: MyAjaxRequest(\"ajmn\",\"/handle_xsmysqllook.php?state=changed\")'>\n"; while ($detailrow = mysql_fetch_array($dropresult, MYSQL_NUM)) { $toecho .= "<option "; if ($detailrow[0] == $valueselected) {$toecho .= "selected ";} $toecho .= "value='".$detailrow[0]."'>".$detailrow[1]."</option>\n"; } $toecho .= "</select>\n"; mysql_free_result ($dropresult); // Free up the result (Good Practice) } else { // If Query was Null $toecho == "<select size='1' name='problem'><option value='0'>No Result $table query $dropquery</option></select>"; } } else { // If Query was Null $toecho == "<select size='1' name='problem'><option value='0'>ERROR IN $table</option></select>"; } return $toecho; } Link to comment https://forums.phpfreaks.com/topic/53461-how-to-send-variable-on-drop-down-change-for-ajax/ Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.