MBurak Erman MBurak Erman - 5 months ago 8
jQuery Question

How to change given input radio value with Jquery?

I have a basic radio button and want to change its value. I tried this but it did not work. It gave me an

[object Object]
error.

<input type="radio" name="myname" value="horse">


var myval = $("input:radio").val(["cat"]);
alert(myval);


How can I do it?

Answer

JSFIDDLE DEMO

var myval = $("input:radio").val("cat"); // remove []
alert(myval.val()); // alert the value, not the jquery selector
Comments