• 0

This does not work


Question

Hello 

 

why have I never head of option list?Is it deprecated?

 

Also this dont work I copied it directly from the book

 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<head>
<title>Dynamically Change Option List</title>
<script language="Javascript" type="text/javascript">
<!--
function ResetOptionList(ElementValue)
{
with (document.forms.Contact)
if (ElementValue == 1)
{
OptionList [0].text = "Classic"
OptionList [0].value = 1
OptionList [1].text = "Police Cruiser"
OptionList [1].value = 2
}
if (ElementValue == 2)
{
OptionList [0].text = "Ford"
OptionList [0].value = 1
OptionList [1].text = "Chevy"
OptionList [1].value = 2
}
}
}
-->
</script>
</head>
<body>
<FORM name="Contact"
action="http://www.jimkeogh.com" method="post">
<P>
<select name="OptionList" size="2">
<option Value=1>Classic
<option Value=2>Police Cruiser
</select>
<BR>
<INPUT TYPE="radio"
name="vehicles" checked="true"
value=1 onclick ="
ResetOptionList(this.value)">Motorcycles
<INPUT TYPE="radio"
name="vehicles" Value=2 onclick="
ResetOptionList(this.value)">Cars
<BR>
<INPUT name="Submit" value="Submit" type="submit"/>
<INPUT name="Reset" value="Reset" type="reset">
</P>
</FORM>
</body>
</html>
Link to comment
Share on other sites

4 answers to this question

Recommended Posts

  • 0

Got some mismatched brackets in there specifically no opening "{" after the "with" statement... fixed up and works fine.  Tabbing the code and using the JavaScript console (F12 for developer tools) shows the error.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR...nsitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Dynamically Change Option List</title>
<script language="Javascript" type="text/javascript">
<!--

function ResetOptionList(ElementValue)
{

	with (document.forms.Contact)
	{
		if (ElementValue == 1)
		{
	
			OptionList[0].text = "Classic"
			OptionList[0].value = 1
			OptionList[1].text = "Police Cruiser"
			OptionList[1].value = 2
		}
		if (ElementValue == 2)
		{
			OptionList[0].text = "Ford"
			OptionList[0].value = 1
			OptionList[1].text = "Chevy"
			OptionList[1].value = 2
		}
	}
}

-->
</script>
</head>
<body>
<FORM name="Contact" action="http://www.jimkeogh.com" method="post">
<P>
<select name="OptionList" size="2">
<option Value=1>Classic
<option Value=2>Police Cruiser
</select>
<BR>
<INPUT TYPE="radio" name="vehicles" checked="true" value=1 onclick ="ResetOptionList(this.value)">Motorcycles
<INPUT TYPE="radio" name="vehicles" Value=2 onclick="ResetOptionList(this.value)">Cars
<BR>
<INPUT name="Submit" value="Submit" type="submit"/>
<INPUT name="Reset" value="Reset" type="reset">
</P>
</FORM>
</body>
</html>
  • Like 3
Link to comment
Share on other sites

  • 0

OK cool I will try it I copied it directly from the text book so if its not written correctly I am just gonn move on

 

A lot of learning to program (regardless of language) is understanding the code of others, it's faults, and how to improve it.  Rather than copy and paste mindlessly, take the time to understand what's happening.  You'll learn a lot faster from the buggy code of others !

Link to comment
Share on other sites

This topic is now closed to further replies.
  • Recently Browsing   0 members

    • No registered users viewing this page.