www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] change a label at page load based on radio button

  1. #1
    Join Date
    Mar 2010
    Posts
    3

    resolved [RESOLVED] change a label at page load based on radio button

    Hi All,
    I have a webpage which has two radio buttons. There is a label also in the web page. I want the label string to be based on the radio button status. I am able to change when somebody press the radio button using "onclick" function, but now when the page is reloaded.
    Here is my code
    Code:
    <body leftmargin="10" rightmargin="10" topmargin="0"  >
    <script type="text/javascript">
    function changeText(val)
    	{
    		if (val==1){
    		 document.getElementById('usemobemail').innerHTML = 'Mobile No';
    		}
    		else if (val==2)
    		{
    		document.getElementById('usemobemail').innerHTML = 'Email ID';
    		}
    	}
    
    </script>
    
    
     
    <html:form action="register" method="post" focus="newusername">
    <center>
    <table border="0" cellpadding="2" cellspacing="12" style="border-collapse: collapse" bordercolor="#111111" width="100%" id="AutoNumber3">
       <tr> <td width="100%" colspan="6" align="center" valign="top"><html:errors/></td>
       </tr>
    	<tr>
          
    		<td width="10%"  colspan="2" align="center">
                   <html:radio property="regradio"  id='viamobi'  VALUE="viamob" onclick="changeText(1)"></html:radio>
    
                 Register via mobile number</td>
    		
      		<td width="10%" colspan="2" align="center">
               <html:radio property="regradio" id='viaAAsys'  onclick='changeText(2)' VALUE="viaAA" ></html:radio>
    
                Register via AA System number </td>
    		
    	</tr>
    <tr>
            <td width="10%">&nbsp;</td> 
    		<td width="10%"><font face="Verdana" size="2"><label id ='usemobemail' >Mobile No</label></font></td>
    		 
    		<td width="10%">
                    <html:text property='regusing' /></td>
    		<td width="10%">&nbsp;</td>		
       </tr> 
    
      </table>
     </center>
     
     
      	</html:form>
      
    </table>
    </body>
    I want the highlighted label value to be changed based on the radio button value at the start up itself( ie if the page get reloaded if some error has happend at filling the form)

  2. #2
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Code:
    window.onload=function() {
    var val = (document.forms[0].regradio[0].checked)? 1 : 2;
    changeText(val);
    };
    At least 98% of internet users' DNA is identical to that of chimpanzees

  3. #3
    Join Date
    Mar 2010
    Posts
    3
    Cool,
    that worked. Thank you for the help

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles