jabbawabba
jabbawabba

Reputation: 69

Two arguments Javascript function

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?

Upvotes: 1

Views: 70

Answers (2)

ArthurChamz
ArthurChamz

Reputation: 2049

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>

Upvotes: 3

p.s.w.g
p.s.w.g

Reputation: 149020

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')">

Upvotes: 3

Related Questions