Arguments are not passed in function calls in the usual way in on-event attributes. There can't be anything in the parentheses after the function name.
Remember that this part is HTML, not JavaScript. The rules are different.
Also, the syntax is different, because the language must be identified. Example:
onclick="JavaScript:calcalot()"
I know this example works.
The following part means absolutely NOTHING in the HTML part of a web page:
window.document.builder.firstDrop.options[selectedIndex].text
This causes errors in the HTML parsing. You have to place this object inside the JavaScript code, not in the HTML code. Also, selectedIndex is undefined.
Also, don't use HTML comments to hide JavaScript. It causes errors in newer browsers. Use a separate file.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
That is correct. The JS file is not part of the source being rendered.
MidiMagic
Nearly a Senior Poster
3,319 posts since Jan 2007
Reputation Points: 730
Solved Threads: 182
A simple script to give you something to chew on:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<title>Test Page</title>
<script type="text/javascript">
function doChange(srcE, targetId)
{
var val = srcE.options[srcE.selectedIndex].value;
var targetE = document.getElementById(targetId);
alert(val);
removeAll(targetE);
if(val == 'languages')
{
addOption('C++', targetE);
addOption('Java', targetE);
addOption('Scheme', targetE);
}
else if(val == 'tools')
{
addOption('Visual Studio', targetE);
addOption('Netbeans', targetE);
addOption('Eclipse', targetE);
}
}
function addOption(value, e)
{
var o = new Option(value);
try
{
e.add(o);
}
catch(ee)
{
e.add(o, null);
}
}
function removeAll(e)
{
for(var i = 0, limit = e.options.length; i < limit - 1; ++i)
{
e.remove(1);
}
}
</script>
</head>
<body>
<form action="#">
<select name="selOne" id="selOne" onchange="doChange(this, 'selTwo')">
<option value="default">---Select Something---</option>
<option value="languages">Languages</option>
<option value="tools">Tools</option>
</select>
<select name="selTwo" id="selTwo">
<option value="default">---Select Something---</option>
</select>
</form>
</body>
</html>
~s.o.s~
Failure as a human
11,938 posts since Jun 2006
Reputation Points: 3,281
Solved Threads: 734