rpd
12-01-2003, 09:02 AM
Hi,
I have a question on checking/unchecking radio buttons/checkboxes and clearing textboxes "attached"
to a radio button/checkbox.
This is a simplified example of the HTML for the FORM.
<FORM name="MyForm">
Question 1
<table>
<tr><td><input type=radio name=list1 value=1>Q1 Radio 1</td>
<td><input type=radio name=list1 value=2>Q1 Radio 2</td></tr>
<tr><td><input type=radio name=list1 value=3>Q1 Radio 3</td>
<td><input type=radio name=list1 value=4>Q1 Radio 4</td>
<td><input type=text name=edit1a size=40 value=""></td></tr>
<tr><td><input type=radio name=list1 value=5>Q1 Radio 5</td>
<td><input type=radio name=list1 value=6>Q1 Radio 6</td>
<td><input type=text name=edit1b size=40 value=""></td></tr>
<tr><td><input type=radio name=list1 value=7>Q1 Radio 7</td>
<td><input type=radio name=list1 value=8>Q1 Radio 8</td></tr>
</table>
Question 2
<table>
<tr><td><input type=checkbox name=list2 value=1>Q2 Checkbox 1</td></tr>
<tr><td><input type=checkbox name=list2 value=2>Q2 Checkbox 2</td></tr>
<tr><td><input type=checkbox name=list2 value=3>Q2 Checkbox 3</td>
<td><input type=text name=edit2 size=40 value=""></td></tr>
<tr><td><input type=checkbox name=list2 value=4>Q2 Checkbox 4</td></tr>
</table>
</FORM>
In reality a form will contain 1 to N radio button groups and/or checkbox groups, and each group
can have 0 to N textboxes attached to individual buttons/checkboxes. Therefore the Javascript should
work with any number of groups and any number of textboxes in a group.
The name of a group is always "LIST" and a number, but the numbering of the lists is not sequential
(groups in 1 form could have the names LIST11 and LIST19).
The name of a textbox is always "EDIT" and a number, but again the numbering is not sequential,
for instance "EDIT15" and "EDIT23".
What I would like to achieve through Javascript is:
A. when a user enters a textbox the preceding radio/checkbox should be checked.
So entering textbox "edit1a" should check "Q1 radio 4" in radio button group "list1".
B. when a user leaves a textbox and the textbox is empty, the preceding radio/checkbox should be unchecked.
So when leaving textbox "edit1a" and this textbox is empty, uncheck "Q1 radio 4" in radio button group "list1".
C. when a user clicks a radio button/checkbox preceding a textbox, the textbox should get focus.
So clicking "Q1 radio 4" in radio button group "list1" should move focus to "edit1a".
D. when a user selects a radio button all textboxs attached to other radio buttons in the radio button group
should be cleared.
So when "Q1 radio 1" is selected, the textboxes "edit1a" and "edit1b" should be cleared.
E. when a user deselects a check box attached to a textbox, that texbox should be cleared.
So when "Q2 Checkbox 3" is deselected, textbox "edit2" should be cleared.
All this functionality has to be "real time", I don't want to wait for the user submitting the form.
The main problem is that the HTML for the FORM is generated by an external application, and that
I CAN'T INFLUENCE this generated HTML. So, I can't use inline event handlers. I can however use Javascript
by adding a SCRIPT-tag in the HEAD-section.
Can anyone help?
I have a question on checking/unchecking radio buttons/checkboxes and clearing textboxes "attached"
to a radio button/checkbox.
This is a simplified example of the HTML for the FORM.
<FORM name="MyForm">
Question 1
<table>
<tr><td><input type=radio name=list1 value=1>Q1 Radio 1</td>
<td><input type=radio name=list1 value=2>Q1 Radio 2</td></tr>
<tr><td><input type=radio name=list1 value=3>Q1 Radio 3</td>
<td><input type=radio name=list1 value=4>Q1 Radio 4</td>
<td><input type=text name=edit1a size=40 value=""></td></tr>
<tr><td><input type=radio name=list1 value=5>Q1 Radio 5</td>
<td><input type=radio name=list1 value=6>Q1 Radio 6</td>
<td><input type=text name=edit1b size=40 value=""></td></tr>
<tr><td><input type=radio name=list1 value=7>Q1 Radio 7</td>
<td><input type=radio name=list1 value=8>Q1 Radio 8</td></tr>
</table>
Question 2
<table>
<tr><td><input type=checkbox name=list2 value=1>Q2 Checkbox 1</td></tr>
<tr><td><input type=checkbox name=list2 value=2>Q2 Checkbox 2</td></tr>
<tr><td><input type=checkbox name=list2 value=3>Q2 Checkbox 3</td>
<td><input type=text name=edit2 size=40 value=""></td></tr>
<tr><td><input type=checkbox name=list2 value=4>Q2 Checkbox 4</td></tr>
</table>
</FORM>
In reality a form will contain 1 to N radio button groups and/or checkbox groups, and each group
can have 0 to N textboxes attached to individual buttons/checkboxes. Therefore the Javascript should
work with any number of groups and any number of textboxes in a group.
The name of a group is always "LIST" and a number, but the numbering of the lists is not sequential
(groups in 1 form could have the names LIST11 and LIST19).
The name of a textbox is always "EDIT" and a number, but again the numbering is not sequential,
for instance "EDIT15" and "EDIT23".
What I would like to achieve through Javascript is:
A. when a user enters a textbox the preceding radio/checkbox should be checked.
So entering textbox "edit1a" should check "Q1 radio 4" in radio button group "list1".
B. when a user leaves a textbox and the textbox is empty, the preceding radio/checkbox should be unchecked.
So when leaving textbox "edit1a" and this textbox is empty, uncheck "Q1 radio 4" in radio button group "list1".
C. when a user clicks a radio button/checkbox preceding a textbox, the textbox should get focus.
So clicking "Q1 radio 4" in radio button group "list1" should move focus to "edit1a".
D. when a user selects a radio button all textboxs attached to other radio buttons in the radio button group
should be cleared.
So when "Q1 radio 1" is selected, the textboxes "edit1a" and "edit1b" should be cleared.
E. when a user deselects a check box attached to a textbox, that texbox should be cleared.
So when "Q2 Checkbox 3" is deselected, textbox "edit2" should be cleared.
All this functionality has to be "real time", I don't want to wait for the user submitting the form.
The main problem is that the HTML for the FORM is generated by an external application, and that
I CAN'T INFLUENCE this generated HTML. So, I can't use inline event handlers. I can however use Javascript
by adding a SCRIPT-tag in the HEAD-section.
Can anyone help?