Javascript HELP PLEASE!

I am building a website for my own comp buisness, and i am adding some javascript and php so users can add options, therfore changing respective pictures etc., or variable amounts(total price of product)<br />
For some reason, when i run this on msie, it says:<br />
<br />
A runtime error has occurred.Do you wish to debug? line:21 error: Invalid character.<br />
<br />
Here is the script: (Note, this is just a very simple test I am doing before i actually make one for the site)<br />
<br />
<html><br />
<head><br />
<br />
<script type="text/javascript"><br />
function ChangeImg(img, newimg)<br />
{<br />
img.src= <!-- m --><a class="postlink" href="http://www.webdeveloper.com/forum/archive/index.php/newimg;">http://www.webdeveloper.com/forum/archi ... hp/newimg;</a><!-- m --><br />
location.reload;<br />
}<br />
function Addpricec(inprice)<br />
{<br />
caseprice.value=inprice;<br />
//location.reload;<br />
}<br />
<br />
</script><br />
<br />
</head><br />
<body><!-- THIS IS TO BE INSERTED IN BUY LAYER --><br />
<input type="hidden" name="caseprice" value=0><br />
<select name="Case" value="select a case"><br />
This is the start of line 21<option value="X-Dreamer II"; onclick="ChangeImg(blah, foldername\imgname);Addpricec(70)">woo</option>This is the end of line 21<br />
<!-- Add more options if needed --> <br />
<br />
<br />
</select><br />
<!-- /where image is displayed/ img name="blah"...... --><br />
<br />
</body><br />
</html><!--content-->Well here's your code as it stands:<option value="X-Dreamer II"; onclick="ChangeImg(blah, foldername\imgname);Addpricec(70);">And here's what it should look like:<option value="X-Dreamer II"; onclick="ChangeImg('blah', 'foldername\imgname');Addpricec(70);return true;">You are passing strings to a JavaScript function, strings need to be quoted. There are certain types of data that don't need to be quoted such as numbers and boolean values.<!--content-->Thanks a lot, are the return and true things at the end needed?<!--content-->The return true; is there to make sure that no matter what happens with the JavaScript the HTML will continue as normal. For instance, if there was a JavaScript error the HTML might stop dead in it's tracks, but with the return true; it will allow the browser onto non-JavaScript functionality.<br />
Apart from that, it's a good habit to pick up, off the top of my head the only time that I don't use return true/false; in an event handler is with onload.<!--content-->
 
Back
Top