This is simple code –
$(document).ready(function() {
var genvalue="";
$("input:radio[name=gender]").click(function() {
genvalue = $(this).val();
alert (genvalue);
});
alert (genvalue);
//genvalue = $('#gender').val();
//alert (genvalue);
value = $("#edu_det1").val();
more code.................goes ......
I want value of alert (genvalue) to alert even if it is not call by click event but when radio button is click the value alerted by first alert while for second out of function is not alerting correct value. I give empty values.
The genvalue is alerted when the radio button is clicked and also as soon as the document ready event is fired. The second is fired first and it will not have any value since you declared at top as
If you want to alert the correct value either way, try this fiddle