How to Use Javascript with ASP RadioButton?http://forums.asp.net/t/1088545.aspx/1?How+to+Use+Javascript+with+ASP+RadioButton+Wed, 05 Jan 2011 03:47:49 -050010885451625995http://forums.asp.net/p/1088545/1625995.aspx/1?How+to+Use+Javascript+with+ASP+RadioButton+How to Use Javascript with ASP RadioButton? <p>Hello,</p> <p>&nbsp;&nbsp;&nbsp; I have to do the validation on the Client Side when the one of the Radio Button Clicked from 3 of them. I know how to write the JavaScript Function but i am confused where i have to use this function by using ASP Radio Buttons.</p> <p>&nbsp; I mean on which event of the RadioButton i have to fire the function of javascript. Because there is no any client side event like onClientClick on ASP radiobutton.</p> <p>&nbsp;</p> <p>So, Please help me to solve this problem.</p> <p>&nbsp;</p> <p>Thanks</p> <p>&nbsp;</p> 2007-03-19T05:06:10-04:001626181http://forums.asp.net/p/1088545/1626181.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>Hi,</p> <p>there must be a Button control on which you will be doing some functionality after entering your data. You have to call the javascript on that button. In short the final level of your page on which by click you will perform your operation.</p> <p>Hope it will sort out your problem</p> <p>Thanks and best regards,</p> 2007-03-19T08:14:43-04:001626566http://forums.asp.net/p/1088545/1626566.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? But i don't want to put the button control. i want to fire this on Radio button click so hw can i do this. 2007-03-19T13:57:32-04:001626592http://forums.asp.net/p/1088545/1626592.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>Hi SPPatel,</p> <p>you will need the <strong>onmousedown </strong>javascript event. The visual studio IDE will tell you that it doesn't exist, but when your page is rendered out as html,<br> the radio button will become a 'input' and it will have the correct event attached on the client side.<br> <br> Something like this...<pre class="prettyprint">&lt;!DOCTYPE html PUBLIC &quot;-//W3C//DTD XHTML 1.0 Strict//EN&quot; &quot;http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd&quot;&gt; &lt;html xmlns=&quot;http://www.w3.org/1999/xhtml&quot;&gt; &lt;head&gt; &lt;title&gt;test&lt;/title&gt; &lt;meta http-equiv=&quot;Content-Type&quot; content=&quot;text/html; charset=ISO-8859-1&quot; /&gt; &lt;script type=&quot;text/javascript&quot;&gt; function clickCheck(obj) { if (obj.checked) { alert(&quot;Already checked&quot;); } } &lt;/script&gt; &lt;style type=&quot;text/css&quot;&gt;&lt;/style&gt; &lt;/head&gt; &lt;body&gt; &lt;input type=&quot;radio&quot; onmousedown=&quot;clickCheck(this)&quot; name=&quot;Radio1&quot; /&gt;&lt;br /&gt; &lt;input type=&quot;radio&quot; name=&quot;Radio2&quot; /&gt; &lt;/body&gt; &lt;/html&gt;</pre>&nbsp;</p> 2007-03-19T14:13:50-04:001626665http://forums.asp.net/p/1088545/1626665.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>Hi. Suppose you have 3 Radiobuttons.. You will be validating on some button control. Please find below how to do it step by step.</p> <p>Step1: Setup your radio buttons on aspx page.</p> <p><font color="#0000ff" size="2">&lt;</font><font color="#800000" size="2">strong</font><font color="#0000ff" size="2">&gt;</font><font size="2"> Some Heading</font><font color="#0000ff" size="2">&lt;/</font><font color="#800000" size="2">strong</font><font color="#0000ff" size="2">&gt;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#800000" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#800000" size="2">RadioButton</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;Radio1&quot;</font><font size="2"> </font><font color="#ff0000" size="2">GroupName</font><font color="#0000ff" size="2">=&quot;Flag&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">=&quot;DNR&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</font><font color="#ff0000" size="2">&amp;nbsp;</font></p> <p><font color="#0000ff" size="2">&lt;</font><font color="#800000" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#800000" size="2">RadioButton</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;Radio2&quot;</font><font size="2"> </font><font color="#ff0000" size="2">GroupName</font><font color="#0000ff" size="2">=&quot;Flag&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">=&quot;RE&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</font><font color="#ff0000" size="2">&amp;nbsp;</p> </font><font size="2"> <p></font><font color="#0000ff" size="2">&lt;</font><font color="#800000" size="2">asp</font><font color="#0000ff" size="2">:</font><font color="#800000" size="2">RadioButton</font><font size="2"> </font><font color="#ff0000" size="2">ID</font><font color="#0000ff" size="2">=&quot;Radio3&quot;</font><font size="2"> </font><font color="#ff0000" size="2">GroupName</font><font color="#0000ff" size="2">=&quot;Flag&quot;</font><font size="2"> </font><font color="#ff0000" size="2">runat</font><font color="#0000ff" size="2">=&quot;server&quot;</font><font size="2"> </font><font color="#ff0000" size="2">Text</font><font color="#0000ff" size="2">=&quot;RI&quot;</font><font size="2"> </font><font color="#0000ff" size="2">/&gt;</p> </font><font size="2"> <p>Step2: You have to declare some button/imagebutton or somthing else to validate. I suppose you have button cmdSave for validation.</p> <p>Step3: in code behind of page On Page Load, you have to call javascript function of validation. i.e</p> <font size="2"> <p>cmdSave.Attributes.Add(</font><font color="#800000" size="2">&quot;onClick&quot;</font><font size="2">, </font><font color="#800000" size="2">&quot;Javascript:checkFlag()&quot;</font><font size="2">);</font></p> <p><font size="2">Step4: You have to declare function checkFlag() in your aspx page. i.e</font></p> <font size="2"><font color="#0000ff" size="2"> <p>function</font><font size="2"> checkFlag()</p> <p>{</p> <p></font><font color="#0000ff" size="2">event</font><font size="2">.returnValue = </font><font color="#0000ff" size="2">false</font><font size="2">;</p> <p></font><font color="#0000ff" size="2">var</font><font size="2"> DNR = document.getElementById(</font><font color="#800000" size="2">'&lt;%= RadioDNR.ClientID %&gt;'</font><font size="2">).checked;</p> <p></font><font color="#0000ff" size="2">var</font><font size="2"> RE = document.getElementById(</font><font color="#800000" size="2">'&lt;%= RadioRE.ClientID %&gt;'</font><font size="2">).checked;</p> <p></font><font color="#0000ff" size="2">var</font><font size="2"> RI = document.getElementById(</font><font color="#800000" size="2">'&lt;%= RadioRI.ClientID %&gt;'</font><font size="2">).checked;</p> <p>&nbsp;</p> <p></font><font color="#0000ff" size="2">if</font><font size="2"> (DNR == </font> <font color="#0000ff" size="2">false</font><font size="2"> &amp;&amp; RE == </font><font color="#0000ff" size="2">false</font><font size="2"> &amp;&amp; RI == </font><font color="#0000ff" size="2">false</font><font size="2">)</p> <p>{</p> <p>alert (</font><font color="#800000" size="2">'Please Specify one of the Flags'</font><font size="2">);</p> <p>}</p> <p></font><font color="#0000ff" size="2">else</font><font size="2"> </p> <p>{</p> <p></font><font color="#0000ff" size="2">event</font><font size="2">.returnValue = </font><font color="#0000ff" size="2">true</font><font size="2">;</p> <p>}</p> <p>&nbsp;</p> <p>}</p> <p>&nbsp;</p> <p>You have to do&nbsp; nothing else. I am sure it will resolve your problem. If this is the solution of your problem, please mark this post as resolved. Thanks</p> </font></font></font> <p><font size="2"></p> </font> 2007-03-19T15:00:29-04:001627075http://forums.asp.net/p/1088545/1627075.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p><strong>Hi fahiemulleh ,</strong></p> <p>&nbsp;</p> <p>&nbsp;</p> <p>Ya, this is the right way but i don't want to fired the function on any button clicked events. I want to do this using Click events on RadioButton. So what i have to do.</p> 2007-03-19T19:07:07-04:001627092http://forums.asp.net/p/1088545/1627092.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>Hi <strong>KBrocksi_SEC,</strong></p> <p><strong>&nbsp; Thanks for the reply. But after that how can i get the value(is it checked or not)&nbsp;of html radio on my .aspx page. </strong></p> <p><strong></strong>&nbsp;</p> <p><strong>Please reply me.</strong></p> <p><strong></strong>&nbsp;</p> <p><strong>Thanks</strong></p> 2007-03-19T19:16:28-04:001627838http://forums.asp.net/p/1088545/1627838.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>You have an event CheckedChanged of Radiobutton. Call javascript validation function from this event. i.e</p> <p>Radio1.Attributes.Add(&quot;onClick&quot;,&quot;javascript:checkFlags()&quot;)</p> <p>&nbsp;</p> <p>let me know if the problem is still not resolved and if resolved, please mark this post as resolved.</p> 2007-03-20T06:23:04-04:001802070http://forums.asp.net/p/1088545/1802070.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>HI i am used as u specified but the problem is after getting the client response then the server event is not raising...</p> <p>My objective is on clicking radiobutton then confirm must popup and if user press ok then the server event of radiobutton must raise otherwise it should not..</p> <p>And i assigned the javascript funtion to radiobutton control thru control.attribute.add(onclick,return funname()) and in server event i wrote some code but is not raising even the user selects OK from confirm button</p> <p>&nbsp;</p> <p>why the event is not raising?</p> <p>regards</p> <p>pandi G S</p> 2007-07-13T10:16:35-04:004181633http://forums.asp.net/p/1088545/4181633.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>I&nbsp;know this thread is old, but for everyone's reference:</p> <p>&nbsp;</p> <p>The radio button is rendered as &lt;span&gt;&lt;input&gt;&lt;label&gt;&lt;/span&gt; ( when text is set to display on the right).</p> <p>By default, the Radiobutton.Attributes.Add() method will add attributes to the &lt;span&gt;, and in response to selarom's post, &quot;onselect&quot; is not a valid javascript event for the span element.</p> <p>The radiobutton and checkbox both support two additional Attribute collections:&nbsp; InputAttributes (for attributes to add to the radio button or checkbox) and LabelAttributes (for attributes to be added to the text of the radio button).</p> <p>&nbsp;</p> <p>So for selarom, use:&nbsp; rad.InputAttributes.Add(&quot;onselect&quot;, &quot;myJsFunction()&quot;)</p> 2010-11-23T18:43:48-05:004238367http://forums.asp.net/p/1088545/4238367.aspx/1?Re+How+to+Use+Javascript+with+ASP+RadioButton+Re: How to Use Javascript with ASP RadioButton? <p>perhaps radio button is not exactly the correct user interface control for your needs?&nbsp; maybe 3 image buttons would have been better?<br> </p> <p><br> </p> 2011-01-05T03:47:49-05:00