Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Rhinorhino on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help with script, passing variables

Status
Not open for further replies.

pmcnally

Programmer
Joined
Apr 7, 2006
Messages
3
Location
US
I am having two problems with my javascript:

First Error: (on page load)
Line 22, Char 41, Error: Unterminated string constant

Second Error: (when you click on one of the links)
Line 32, Char 1, Error: Object expected

here is the source:

<html>
<head>
<script language="javascript">
function populateBox2(title, desc, pic1, pic2, pic3, pic4, pic5, pic1_name, pic2_name, pic3_name, pic4_name, pic5_name)
{
text1 = "<h2>title</h2>desc<br><a href="#" onClick='populateBox1(pic1)'>pic1_name</a> <a href="#" onClick='populateBox1(pic2)'>pic2_name</a> <a href="#" onClick='populateBox1(pic3)'>pic3_name</a> <a href="#" onClick='populateBox1(pic4)'>pic4_name</a> <a href="#" onClick='populateBox1(pic5)'>pic5_name</a> "

document.getElementById("box2").innerHTML = text1;
}
function populateBox1(picName)
{
document.box1.src = "images/" + picName;
}
</script>
</head>
<body>
<table><tr><td><img src="images/i3.jpg" id="box1" width="300" height="150"></td>
<td><div id="box2">&nbsp;</div></td></tr></table>
<br>
<table><tr>
<td align="center">
<a href="#" onClick='populateBox2("Number 31", "paintballs `R' us1", "orange21", "indigo31", "mauve41", "love51", "oh yeah61", "i4.jpg", "i10.jpg", "i7.jpg", "i11.jpg", "i2.jpg"); return false'>
<img src="images/i4.jpg">
<br>
Number 31 - $6.991</a></td>
<td align="center">
<a href="#" onClick='populateBox2("Number 24", "oh yeah baby4", "orange", "indigo", "mauve", "love", "oh yeah", "i5.jpg", "i7.jpg", "i8.jpg", "i9.jpg", "i10.jpg"); return false'>
<img src="images/i5.jpg">
<br>
Number 24 - $7.44</a></td>
<td align="center">
<a href="#" onClick='populateBox2("Number 1", "loving you baby, every day, every night, oh yeah", "red", "blue", "loving green", "sea green", "aqua marine", "i6.jpg", "i3.jpg", "i4.jpg", "i5.jpg", "i11.jpg"); return false'>
<img src="images/i6.jpg">
<br>
Number 1 - $7.43</a></td>
<td>&nbsp;</td>
</tr></table>
</body>
</html>

Thank you for you help =)

Light and Love to you all

-Patrick Arden McNally
 
The string error is because you have quotes within quotes:

Code:
var someVar = "<a href="...">"

which just won't work - the JS parser has no way of knowing whether you want to terminate the string or not.

You should escape the inner quotes by putting a backslash before them:

Code:
var someVar = "<a href=[!]\"[/!]...[!]\"[/!]>"

Hope this helps,
Dan

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I fixed part of it, the "paintballs `R' us1" part messed it up as an unterminated string constant, however, now I get this message when I click on a photo:
Line 22, Char 1, Error: Object Expected

Any help would appreciated =)
 
I have fixed this script =)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top