Jump to content

text field & radio buttons


MDanz

Recommended Posts

You can show the button is disable till someone clicks on the radio button and using java script function you can check whether the radio buttons value is selected or not.

 

I have done something like this long time back. but it was not for submit button but if user clicks on radio button then he/she would be able to write something into respective text box.

 

please check out the following code may it ll help you. :D

 

php code:

 <td width="101%" valign="top" colspan="2">Habits and Lifestyles</td>
  </tr>
  <tr>
  <td width="50%" valign="top">Cigarettes</td>
    <td width="50%">
  <p class="MsoNormal"><input type="radio" name="cigarette" value="Y" onClick="decide('enable')"><b>
      <input type="text" name="cigarette_per_day" size="20"></b> cigarettes/day ×
    <input type="text" name="years_cigarette" size="20">year </p>
    <p><input type="radio" name="cigarette" value="N" onClick="decide('enable')"><b> </b>Quit
    since <input type="text" name="quit_cigarette_since" size="20">year after smoking/chewing for
    <input type="text" name="quit_cigarette_after" size="20">year </p></td>
</tr>

 

JS for this

function decide(disorenable)
{

    var num = document.cont.elements.length
   //var current = 0

   if(disorenable == 'disable')
  {


document.cont.cigarette_per_day.disabled  = true
document.cont.years_cigarette.disabled   = true
document.cont.tobacco_per_day.disabled   = true
document.cont.tobacco_years.disabled     = true
document.cont.quit_since.disabled = true
document.cont.quit_after.disabled = true



   }
   else
{

document.cont.cigarette_per_day.disabled = false
document.cont.years_cigarette.disabled = false
document.cont.tobacco_per_day.disabled = false
document.cont.tobacco_years.disabled = false
document.cont.quit_since.disabled = false
document.cont.quit_after.disabled = false


}

}

See, i have checked the following code. Do you want to do somthing like this?

 

<html>
<head>
<script>
function decide3(disorenable)
{
var num = document.cont.elements.length
   //var current = 0
if(disorenable == 'disable')
{
document.cont.cups_per_day.disabled = true
}
   else
{
document.cont.cups_per_day.disabled = false
}

}

</script>
</head>
<body>
<form action="<?=$PHP_SELF;?>" method="post" name="cont">

<table>
<tr>
    <td width="50%" valign="top">
       Tea/Coffee: </td>
    <td width="50%"><input type="radio" name="tea_coffee" value="N" onClick="decide3('disable')"> No
    <input type="radio" name="tea_coffee" value="Y" onClick="decide3('enable')"> Yes
    <input type="text" name="cups_per_day" size="20">cups/day</td>
  </tr>
</form>
</table>
</body>
</html>

yeh similar, i've changed it to make it easier for me... 

 

e.g.

if radiobutton1 is pressed then bring forward layer1(which has the submit button). 

 

 

^^

This way i can do as many submit buttons as i want because layers can overlap.

 

The only problem i have is how to slot in the command

if($_GET['RadioGroup1']== 1 )

\\bring layer1 to front

 

whats the code to bring layers to the front?  thx for the help btw

 

 

 

 

 

if($_GET['RadioGroup1']== 1 )

 

Using this you must be storing your radio buttons value if i am not wrong. so i assume that you are doing something like this. So you can fetch the value and according to it you can adjust your code.

 

Is this something similar you want that?

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.