Jump to content


Photo

Drop Down List Problem


  • Please log in to reply
3 replies to this topic

#1 lilywong

lilywong
  • Members
  • PipPipPip
  • Advanced Member
  • 56 posts

Posted 22 February 2006 - 02:52 PM

This is a simply drop down box with three selections, one, two and three. while i try to select option two, i need a message box pop up showing two, if i select option three, the message box will show three. However i got the below error while i select it. Any problem with this simple codes ?

Error: 'document.form1.select.value' is null or not an object
==================================================================

<?
print_r($_POST); print"<br>";
print_r($_GET);print"<br>";
$a = $_GET[select];
print $a;
?>

<select name='select' onchange='go(this)'>
<option value='one'>one</option>
<option value='two'>two</option>
<option value='three'>three</option>
</select>
<form name='form1'>
<input type='hidden' name='txtSelect' value='select'>
</form>

<script type="text/javascript">
function go(opt)
{
var name = document.form1.select.value;
alert (name);
}
</script>


#2 kenrbnsn

kenrbnsn
  • Staff Alumni
  • Advanced Member
  • 8,235 posts
  • LocationHillsborough, NJ, USA

Posted 22 February 2006 - 03:13 PM

This is a Javascript question, not a PHP question.

Create a normal hard coded HTML form and get your javascript working, then put in your PHP.

Ken

#3 hitman6003

hitman6003
  • Members
  • PipPipPip
  • Advanced Member
  • 1,807 posts

Posted 22 February 2006 - 11:11 PM

Change your onchange to this:

onchange="javascript: go(this, this.selectedIndex);"

Change your JS function to this:

<script type="text/javascript">
function go(x, y) {
alert (x[y].value);
}
</script>

Please post your questions in the proper forum in the future...this should be in the Javascript forum.

#4 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 23 February 2006 - 01:25 AM

vroom - moved to javascript forum
Legend has it that reading the manual never killed anyone.
My site




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users