Reputation:
i am calling this function
<script>
function getvalue(){
$(document).ready(function(){
$("[type='radio']").change(function ()
{
var hidden = $(this).prevAll("[type='hidden']");
var h3 = $(this).prevAll("h3");
hidden.val(h3.text());
//alert(hidden.val());
});
});
}
</script>
what happens is, clicking on any radio button doesnt fire the function.. but clicking on second does, i have already used document.ready but its not working.. any point which i am missing? Thanx :)
Upvotes: -1
Views: 49
Reputation: 1960
Remove function getvalue(){..... or you call the function getvalue. This code not register the event handler "ready" and so not fire
<script>
$(document).ready(function(){
$("[type='radio']").change(function ()
{
var hidden = $(this).prevAll("[type='hidden']");
var h3 = $(this).prevAll("h3");
hidden.val(h3.text());
//alert(hidden.val());
});
});
</script>
or
<script>
function getvalue(){
$(document).ready(function(){
$("[type='radio']").change(function ()
{
var hidden = $(this).prevAll("[type='hidden']");
var h3 = $(this).prevAll("h3");
hidden.val(h3.text());
//alert(hidden.val());
});
});
}
getvalue();
</script>
Upvotes: 1
Reputation: 3481
your setting up the change hook for all radio buttons, when you execute the function for the first time. Thus, no change handler attached for the first.
remove the outer function wrapper to install the hook on dom-ready:
<script>
$(document).ready(function(){
$("[type='radio']").change(function ()
{
var hidden = $(this).prevAll("[type='hidden']");
var h3 = $(this).prevAll("h3");
hidden.val(h3.text());
//alert(hidden.val());
});
});
</script>
Upvotes: 1