Jump to content

Javascript dropdown to pass variable and call Ajax


tdors

Recommended Posts

Can't figure it out.  I have the full code below, but I'm trying to pull data out of mysql based on the value selected from a drop down box,

 

I have the

 

<select size='1' name='".$selectname."' class='".$dropstyle."' onchange='javascript:  MyAjaxRequest(\"ajmn\",\"/handle_xsmysqllook.php?state=changed\")'>

 

which is fine, and I know how get variables work, but when I want to add to the end - &sellid=<Drop Down Variable> 

 

Thanks in advance for any help!

 

 

 

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.