0

I m trying to pass a simple string parameter to a method. I googled but they are not showing anything relative. I don't know where i am doing a mistake. Here is my JavaScript and HTML code for the same.

function check(var tyt) {
    document.getElementById(""+tyt).checked="checked";
}

Here is my html code:

<input type=radio name="InterestedIn" id="Placement" required value="Placement" /><font onClick="check('Placement')">Placement</font>
1
  • JavaScript doesn't support type-hinting on method parameters, which you may have experience of using in other languages. Commented Apr 7, 2014 at 11:40

1 Answer 1

6
// without the 'var' in parameter list:
function check(tyt) {
  document.getElementById("" + tyt).checked = "checked";
}

And for your HTML, you can achive this without JavaScript:

<label>
  <input type=radio name="InterestedIn" id="Placement" required value="Placement" />
  Placement 
</label>

And one more thing: <font>-Tag is deprecated since 1960 or so. :)

However there is a littel difference between your onclick which will only check the checkbox and the <label> which will also uncheck the box when clicked again.

Sign up to request clarification or add additional context in comments.

1 Comment

@RahulGoel It's true, don't use font tag ;)

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.