[thelist] Simple JavaScript question

john at johnallsopp.co.uk john at johnallsopp.co.uk
Sat Jul 8 11:14:25 CDT 2006


Hi Rick

Thanks, I was almost there, but I still have a problem.

>> <form method='post' action='index.php4' name='giftOpts'><select
>> name='abc' onChange='changePrice(abc)'>";
>>
> You're missing quotes around your abc in onChange='changePrice(abc)'.
> Without quotes, Javascript will treat that as a variable name. If you
> haven't defined a variable abc, this will end up sending "undefined"
> to
> the function. Putting quotes around that will solve your problem;
>
> <select name='abc' onChnage=\"changePrice('abc')\">

Thanks, this:

window.alert ('Debug: Inside javascript: received ' + pOption);

tells me I'm receiving the data OK, it's passing 'size' or 'delivery'
depending on the select tag (but I never get to a later alert).

But

> Here's how I'd change this to get the value of the selected option:
>
> ind = document.getElementById(pOption).selectedIndex;
> val = document.getElementById(pOption).options[ind].value;

is giving me an error (in Firefox 1.0.7/Linux):

Error: document.getElementById(pOption) has no properties


here's all the current code:

<script language='JavaScript'>
function changePrice(pOption)
{
	// get what user selected
	window.alert ('Debug: Inside javascript: received ' + pOption);
	ind = document.getElementById(pOption).selectedIndex;
	val = document.getElementById(pOption).options[ind].value;
	window.alert ('Debug: Inside javascript: changePrice');
	}
</script>

and

$returnString.="<tr><td class='head'>".$value[1]."</td><td><select
name='$value[1]' onChange=\"changePrice('".$value[1]."')\">";

where $value[1] = price, delivery, or whatever.

Am I missing some definition of 'document'?

Thanks for your help.

Cheers
J



More information about the thelist mailing list