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 :)
-
Clicking on second what?Jay Blanchard– Jay Blanchard2014年10月31日 13:16:31 +00:00Commented Oct 31, 2014 at 13:16
-
@JayBlanchard clicking on any other radio button second time..user3239333– user32393332014年10月31日 13:18:12 +00:00Commented Oct 31, 2014 at 13:18
-
1Can you post your HTML?dfsq– dfsq2014年10月31日 13:18:14 +00:00Commented Oct 31, 2014 at 13:18
2 Answers 2
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>
Comments
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>