Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Common Function for Multiple CheckBoxes 1

Status
Not open for further replies.

Deadline

Programmer
Feb 28, 2001
367
US
Hi,

Actually I have 5 check boxes and 5 respective text areas.

My need is if the user types something inside the TextArea, without checking the corresponding checkbox, then the checkbox should automatically get CHECKED.

Similarly, if the user clears any textareas completely, then the checkbox needs to be UNCHECKED.

I am generating the TextAreas and Checkboxes through Response.Write(&quot;<INPUT TYPE=TextArea>&quot;)...... so on.

I thought of having a function to avoid repetition for the five+five controls.

Do you have any other strategy/approach to this problem?

How to do it ?


Thank you in advance


RR
:-(



 
When you're generating you textarea boxes in HTML, do it in a seperate function. Use the content of the textarea box as an argument to that function, and add another argument as the sequence number of the boxes.

At the point where you're generating the box, check if the content is empty or not, and set the 'checked' value of the accompanying checkbox right away; e.g. (pseudocode)

Code:
function GenMyTextBox(byval Counter, byval Content)
     if Trim(Content) <> &quot;&quot; then
        response.Write(&quot;<input name=check&quot; & counter & &quot; type=checkbox checked value=true>&quot;)
     else
        response.Write(&quot;<input name=check&quot; & counter & &quot; type=checkbox value=true>&quot;)
     end if

     response.Write(&quot;<textarea name=text&quot; & counter & &quot;>&quot; & Content & &quot;</textarea>&quot;

     'you could even write some JScript here to 
     'dynamically change the checkbox
end function

call GenMyTextBox(1, Request.Form(&quot;text1&quot;))
call GenMyTextBox(2, Request.Form(&quot;text2&quot;))
call GenMyTextBox(3, Request.Form(&quot;text3&quot;))
call GenMyTextBox(4, Request.Form(&quot;text4&quot;))
'generate submit button here
Yours,

Rob.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top