By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,398 Members | 1,362 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,398 IT Pros & Developers. It's quick & easy.

Problem with input type radio and select name

100+
P: 263
Hi everyone.

My form page htm:

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3.     <script language="javascript">
  4.         function controlla_combo()
  5.         {
  6.             document.form1.Nacionalidad_text.disabled = document.form1.Nacionalidad[0].checked;
  7.             document.form1.Nacionalidad_text.disabled = document.form1.Nacionalidad[1].checked;
  8.         }
  9.     </script>
  10. </head>
  11. <body>
  12.     <form name="form1" action="insert.jsp" method=post> 
  13.     <table>
  14.         <tr>
  15.             <td><input type="radio" name="Nacionalidad" value="1" onclick="controlla_combo();" CHECKED></td>
  16.             <td><input type="radio" name="Nacionalidad" value="0" onclick="controlla_combo();"></td>
  17.             <td><input type="radio" name="Nacionalidad" value="2" onclick="controlla_combo();"></td>
  18.             <td>
  19.                 <select name="Nacionalidad_text" disabled>
  20.  
  21.     <OPTION VALUE="MX">MÚxico</OPTION>
  22.     <OPTION VALUE="IT">Italia</OPTION>
  23.     <OPTION VALUE="ES">Espa˝a</OPTION>
  24.  
  25.                 </select>
  26.             </td>
  27.         </tr>
  28.     </table>
  29.     </form>
  30. </body>
  31. </html>
I need this:

1) If checked input type="radio" name="Nacionalidad" value="1" the select name="Nacionalidad_text" is DISABLE;

2) If checked input type="radio" name="Nacionalidad" value="0" the select name="Nacionalidad_text" is DISABLE;

3) If checked input type="radio" name="Nacionalidad" value="2" the select name="Nacionalidad_text" is ENABLE;


The function function controlla_combo() NOT working... :

1) If checked input type="radio" name="Nacionalidad" value="1" the select name="Nacionalidad_text" is ENABLE;

2) If checked input type="radio" name="Nacionalidad" value="0" the select name="Nacionalidad_text" is DISABLE;

3) If checked input type="radio" name="Nacionalidad" value="2" the select name="Nacionalidad_text" is ENABLE;

Can you help me ?
Aug 14 '09 #1
Share this Question
Share on Google+
2 Replies


Dormilich
Expert Mod 5K+
P: 8,639
your approach to the function is totally wrong. if you want the select enabled, check which radio is checked. (this requires a condition to be tested, thus use if () )
Aug 14 '09 #2

100+
P: 263
OK, thanks x your answer. This code working: :)

Expand|Select|Wrap|Line Numbers
  1. <html> 
  2.     <head> 
  3.     <title>prova</title> 
  4.     <script type='text/javascript'> 
  5.         function controlla(valore) 
  6.         { 
  7.             if(valore==2) 
  8.             { 
  9.                 document.mioform.NazionalitÓ_text.disabled=false; 
  10.             } 
  11.             else 
  12.             { 
  13.                 document.mioform.NazionalitÓ_text.disabled=true; 
  14.             } 
  15.         } 
  16.  
  17.  
  18.  
  19. function submIt(theform) 
  20.  
  21.             var selObj = document.mioform.NazionalitÓ_text; 
  22.             var selIndex = selObj.selectedIndex; 
  23.             if(selIndex==0  && document.mioform.NazionalitÓ_text.disabled==true) 
  24.             { 
  25.                 return true; 
  26.             } 
  27.             else if(selIndex ==0 && document.mioform.NazionalitÓ_text.disabled==false) 
  28.             { 
  29.                 alert("OBBLIGATORIO"); 
  30.                 mioform.NazionalitÓ_text.focus(); 
  31.                 return false; 
  32.             } 
  33.  
  34.  
  35.  
  36.   return(true);
  37. }        
  38.     </script> 
  39.     </head> 
  40.  
  41.     <body onload="controlla(0)"> 
  42.         <form id="mioform" name="mioform" method="post" onsubmit="return submIt(this);"> 
  43.  
  44.             A <input onclick="controlla(this.value);" type="radio" name="NazionalitÓ" value="1" CHECKED><br> 
  45.             B <input onclick="controlla(this.value);" type="radio" name="NazionalitÓ" value="0"><br> 
  46.             C <input onclick="controlla(this.value);" type="radio" name="NazionalitÓ" value="2"><br> 
  47.             <br><br> 
  48.             <SELECT NAME="NazionalitÓ_text" SIZE="1"> 
  49.             <OPTION VALUE="">---------------------------</OPTION> 
  50.             <OPTION VALUE="IT">Italiana</OPTION> 
  51.             </SELECT> 
  52.  
  53.             <input type="submit" value="Invia" name="B1">
  54.  
  55.         </form> 
  56.     </body> 
  57. </html>
  58.  
Aug 15 '09 #3

Post your reply

Sign in to post your reply or Sign up for a free account.