Jump to content

How to send variable on Drop Down Change for AJAX


tdors

Recommended Posts

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