Reputation: 13
I have a Java Script that stops working when I try to input two values. This is the script that works:
<HEAD> <script type="text/javascript">
function addsuggest(name)
{
document.getElementById("recipients").innerHTML=document.getElementById("recipients").innerHTML+name+".L ";
}
</script> </HEAD>
<a href=javascript:onClick=addsuggest('3') >click here<a/><br>
<span id=recipients style="color:blue;"> </span>
Nothing fancy. It just adds 3.L in blue color to the end of a line.
I want this function to do some other things so I change function addsuggest(name)
to function addsuggest(name, id)
and onClick=addsuggest('3')
toonClick=addsuggest('3', 'John')
These are the symptoms I have:
javascript:onClick=addsuggest('3'
and not the rest. So it's stopped reading it at the comma. This is the simplest thing I've done with Java Script. It's just inputting values and then printing it. So, what's the matter?
Upvotes: 0
Views: 114
Reputation: 709
You need quotes surrounding the href
attribute (and should place them around all other attributes), otherwise the single quotes around the function parameters will break the link:
<HEAD> <script type="text/javascript">
function addsuggest(name, id)
{
document.getElementById("recipients").innerHTML=document.getElementById("recipients").innerHTML+name+id+".L ";
}
</script> </HEAD>
<a href="javascript:onClick=addsuggest('3', 'John');" >click here<a/><br>
<span id="recipients" style="color:blue;"> </span>
Upvotes: 3
Reputation:
<a href="#" onclick="javascript:addsuggest('3');">...</a>
and for readability:
function addsuggest(name)
{
document.getElementById("recipients").innerHTML += name + ".L";
}
Upvotes: 1