jquery for asp.net sometimes work sometimes doesn't work
-
Hi, I have jquery implemented for the popup confirmation on radio button select. So my radio button has yes or no options. so in each select, the popup should show up and based on the option, it has to hide and show the panel. But the problem is sometimes for the same option, jquery runs and sometimes for the same option jsquery doesn't run. the following jquery is in my aspx page.
<script language="JavaScript" type="text/javascript">
$(document).ready(function() { function confirmDelete() { if (confirm('It will delete your file. Is that Ok?')) { document.getElementById('<%= radbutSelector.ClientID %>').click(); return true; } return false; } </script>
Now i have called this jquery on radio button select like this
And the code behind the radio button select is like this
protected void radbutSelector_Click(object sender, EventArgs e)
{if (radWantEnter.SelectedValue == "Yes") { pnl1.Visible = true; } else { pnl2.Visible = false; } }
sometimes the radbutSelector executes its codes and sometimes its not for the same event. Any idea and any solutions would be great help.
Dhyanga
-
Hi, I have jquery implemented for the popup confirmation on radio button select. So my radio button has yes or no options. so in each select, the popup should show up and based on the option, it has to hide and show the panel. But the problem is sometimes for the same option, jquery runs and sometimes for the same option jsquery doesn't run. the following jquery is in my aspx page.
<script language="JavaScript" type="text/javascript">
$(document).ready(function() { function confirmDelete() { if (confirm('It will delete your file. Is that Ok?')) { document.getElementById('<%= radbutSelector.ClientID %>').click(); return true; } return false; } </script>
Now i have called this jquery on radio button select like this
And the code behind the radio button select is like this
protected void radbutSelector_Click(object sender, EventArgs e)
{if (radWantEnter.SelectedValue == "Yes") { pnl1.Visible = true; } else { pnl2.Visible = false; } }
sometimes the radbutSelector executes its codes and sometimes its not for the same event. Any idea and any solutions would be great help.
Dhyanga
That's a csharp code behind function, there is no Jquery on any example except for $(document).ready. and that's not correct either. You don't need document ready unless your binding events with the document ready. I can't see how confirm delete works, where does the object confirm come from?
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
});
function confirmDelete() { if (confirm('It will delete your file. Is that Ok?')) { document.getElementById('<%= radbutSelector.ClientID %>').click(); return true; } return false; } </script>
-
That's a csharp code behind function, there is no Jquery on any example except for $(document).ready. and that's not correct either. You don't need document ready unless your binding events with the document ready. I can't see how confirm delete works, where does the object confirm come from?
<script language="JavaScript" type="text/javascript">
$(document).ready(function() {
});
function confirmDelete() { if (confirm('It will delete your file. Is that Ok?')) { document.getElementById('<%= radbutSelector.ClientID %>').click(); return true; } return false; } </script>
The script is like this:
<script language="JavaScript" type="text/javascript">
function confirmDelete() { if (confirm('It will delete your file. Is that Ok?')) { document.getElementById('<%= radbutSelector.ClientID %>').click(); return true; } return false; } </script>
Dhyanga
-
The script is like this:
<script language="JavaScript" type="text/javascript">
function confirmDelete() { if (confirm('It will delete your file. Is that Ok?')) { document.getElementById('<%= radbutSelector.ClientID %>').click(); return true; } return false; } </script>
Dhyanga
In Jquery, it's more along the lines of this. I guessed at the ID or the radio button set, won't work, just an example of how to format it. but it's closer to what you want. So it binds the change event to the DOM, and fires the function, passing the event to it. Radio buttons are checkboxs, they act the same, and have the same events, so think of them as checkboxes. If you have a group of them, say 2, then you have to get the selected index of the 2 radio buttons, which is an array of values, from the DOM. That's what the [0] is for. I was about to leave tor the night and sleep, but wanted to help a little more if possible. I can tell your not that familiar with Jquery. If you have an update panel on the page, this won't work after using the update panel once, because the DOM unloaded.
<script language="JavaScript" type="text/javascript">
$(document).ready( function() { $('\[id\*="radbutSelector"\]').change( function(event) { confirmDelete(event); }); }); function confirmDelete(event) { var newradio= $("input\[name='pick\_up\_point'\]:checked")\[0\]; if (newradio===currentradio) return; if (confirm('Address details will be cleared. Continue?')) { clearInputFields(); currentradio= newradio; } else { currentradio.checked= true; } } </script>