1

I'm trying to use two arguments in a function, but it's not working? This is not the final function, I'm just trying to get the arguments to work.

the html:

<div id = "textButton" class = "convertButtonss" onclick = illegal_chr("bin" ,"binary")>
    <p id = "textButton_p">
        txt/dec
    </p>
</div>

the Javascript:

function illegal_chr(name, type) {
    alert(name);
    alert(type);
}

when I click on the div nothing happpens?

1
  • watch your whitespace too... Commented Feb 13, 2014 at 21:52

2 Answers 2

3

Try wrapping the entire attribute value in double quotes, and the string literals in single quotes, or vice versa, like this:

<div … onclick="illegal_chr('bin','binary')">
Sign up to request clarification or add additional context in comments.

Comments

3

Remember that tag attributes in HTML must be surrounded by quotes or double-quotes. Try this:

<div id = "textButton" class = "convertButtonss" onclick = 'illegal_chr("bin" ,"binary")'>
    <p id = "textButton_p">
        txt/dec
    </p>
</div>

5 Comments

attribs need not be quoted unless they have an "=" or " " in them, which this one does but need not to. You also can't have a space after the = of the attrib itself, even if you use quotes further to the right...
Mmm... Been conforming to XHTML for too long. Thanks!
break off those 1999 shackles and run free!
@dandavis—the list of characters in attribute values that must be escaped is " ' ` = < >..
@dandavis—yes, I mis–typed, "escaped" should be "quoted". :-/

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.