PDA

View Full Version : Make input text unfillable if radio answer "N"



mtran
10-31-2006, 11:40 PM
Hi,

I'm working on a form and wondering if there's a script that can do the following.
I have: Q1: radio inputs with 2 options : Yes and No
If somebody clicks Yes, then they go to Q2: fill in some input text fields.
If they click No, they'll skip 2 and go to Q3.

My question is: can we do something with javascript & CSS so that when they click No in Q1, Q2 with input text fields become unfillable, hidden, or at least change colors...

Thanks for help.

tech_support
11-01-2006, 04:34 AM
Unfillable:



function makeUnfillable(){
document.forms['formname'].elements['fieldname'].readonly = "true"
}


Hidden:



function makeHidden(){
document.forms['formname'].elements['fieldname'].style.visiblity = "hidden"
}


Changing Colours:



function changeColor(){
document.forms['formname'].elements['fieldname'].style.bgcolor="color"
}


I think...


Untested.

djr33
11-01-2006, 07:47 AM
Additionally, though, it should be noted that a value already in the box when it is made hidden/inactive may still be sent to the next page.

You could also include field.value = ""; in the functions to be sure of that.