Maybe I’m preaching to the choir. So choir, listen up!
I have seen many posts on this forum that say the script is ‘not working’. Many times the problem is simply a syntax or spelling error. (Missing this or that, or ‘object expected’). 9 times out of 10, the browser will point you to the offending line and you can easily fix the problem.
Is your browser set up to give to you an error message?
IE:
In the status bar you might see a ‘warning’ icon. Double-click and you will get details of the error. While you are at it, check the ‘Always display this message…..’ when debugging.
If there’s no popup message, go to:
Tools::Internet Options::Advanced and, in the Browsing options,
check ‘Display a notification about every script error’.
Netscape & Mozilla:
If the script does not do what you expect, type ‘javascript:’, including the :, (no space) in the address bar and details of your error will be displayed.
[code=php]
<html><head><title>untitled</title>
<script type=”text/javascript”>
<!–
Here’s a simple script but it does NOT work!
function gettotals() {
var qty = document.theform.quantity.value;
var price = document.theform.priced.value;
document.theform.total = qty * price;
}
//–>
</script>
</head>
<body>
<form name=”theform” action=”” onsubmit=”return getTotals()”>
<ul><li><input name=”quantity” type=”text” value=12></li>
<li><input name=”price” type=”text” value=11></li>
<li><input name=”total” type=”text”></li>
<li><input type=”submit” value=”Get Total”></li></ul>
</body>
</html>
This little script has several problems all easily found with the debug tools.
Line 4: ‘Unterminated string constant’. Should be commented out using //
Line 15: ‘Object expected’. Spelling error – javascript is CASE SENSITIVE
Line 7: ‘document.theform.priced.value is null or not an object’. Another spelling error
Line 8: ‘Object doesn’t support this property or method’. Missing the .value
I fixed all the errors and is STILL does not work. Very strange!
You need to ‘return false’ in your function. Otherwise the form will be submitted and return a new page.
(which, in this case, is this page)