Link to home
Start Free TrialLog in
Avatar of Melfeky
Melfeky

asked on

I want iff the user checks the Yes checkbox the text area he can write data into, but if he checks No checkbox the text area is disabled.

Hello all experts,
I have got a form with this structure:
A question       yes       No
Text area

The yes or No fields are check boxses,what i want is that
 if the user checks "Yes" I need for the "Textarea" to become enabled.  If they check "No" or have not selected "Yes" or "No" I need it to be disabled.  Does that make sense?  This would be for all "Yes" or "No" questions in that form, as if the user checks "No" they do not need to add details.
Thanks
Avatar of sorex
sorex


you need to hide/show parts of your form with javascript code unless you don't care if the page needs to refresh then you can do it completely in asp
try this

<form name=form>
<input type=checkbox name=box1 onclick="javascript:check();" checked>
<div id="txt1" style="display:'';"><input type=text name=txt1></div>
</form>

<script language="javascript">
function check()
{if (document.form.box1.checked      ) {document.form.txt1.style.display=''} else {document.form.txt1.style.display='none'}}
</script>
or even better... a modded example with 2 check/text boxes

<form>
<input type=checkbox name=box1 onclick="javascript:check(1);">
<input id=txt1 type=text name=txt1 style="display:'none';">
<br>
<input type=checkbox name=box2 onclick="javascript:check(2);">
<input id=txt2 type=text name=txt2 style="display:'none';">
</form>

<script language="javascript">
function check(id)
{box='box'+id;txt='txt'+id;
if (document.all(box).checked      ) {document.all(txt).style.display=''} else {document.all(txt).style.display='none'}}
</script>
Avatar of Melfeky

ASKER


hello sorex
i have two checkboxses and one text area
<INPUT TYPE="checkbox" VALUE="1" NAME="cb1" <% if cb1 = true then %>checked<% end if %>>
The no Check box
<INPUT TYPE="checkbox" VALUE="1" NAME="cb2" <% if cb2 = true then %>checked<% end if %>>
The text area:
<TEXTAREA NAME="txtTextField" COLS="30"><%= tq1 %></TEXTAREA>

you either use 1 check box or 2 radio buttons, not 2 checkboxes.
Avatar of Melfeky

ASKER

I know , but my form must be like this and cann't  change it to radio buttons so i am using 2 chewckboxses ,
here is an example of the questio so u can get it:
1-  Is the firm delinquent in filing any applicable business tax returns? Yes          No      
           
Text area field
   
why can't you change it?

what if people select both yes & no or nothing at all?
this one works with a yes & no , but the no is useless

<form>
<input type=checkbox name=cb1 onclick="javascript:check(1);"> Yes -
<input type=checkbox name=cb2 onclick="javascript:check(2);"> No


<input id=txtTextField1 type=text name=txtTextField1 style="display:'none';">

<script language="javascript">
function check(id)
{if (document.all('cb'+id).checked      ) {document.all('txtTextField1').style.display=''} else {document.all('txtTextField1').style.display='none'}}
</script>
Avatar of Melfeky

ASKER

i have made the checkbox behave like radio buttons so they will either chooses yes or no
I suggest you stick to only 1 check box (a Yes) or 2 radio buttons.

with 2 checkboxes I can't get my script right
ASKER CERTIFIED SOLUTION
Avatar of sorex
sorex

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of Melfeky

ASKER

hello sorex,
thanks for trying to help.
I thought there might be a solution for this in ASP but it seems that there isn't.
though i have got something in my mind but cann't get it work:
<if cb1= true then%>

<input type=text name="txtTextField1">
<%else%>

<input type=text name="txtTextField1" disabled>

would u tell me whats wrong in my code
thanks
Avatar of Melfeky

ASKER

thanks
this works tho

<%cb1=false

if cb1= true then%>

<input type=text name="txtTextField1">
<%else%>

<input type=text name="txtTextField1" disabled>
<%end if%>

dump cb1 and see if it actually returns a false or true value
Avatar of Melfeky

ASKER

thanks