Did you get a chance to run the HTML file and see?
Ramoji.
Main Topics
Browse All TopicsI want to create a form that has 4 check boxes and an edit button. At least one button has to be checked by the user. When the user clicks the edit button, a sub procedure named Check_box_onClick will be executed.
The sub will put the value of every button that is checked in an array and ask the user to check at least one check box if the user has not choosen any.
How does the VBSript code for that sub look like? I am looking for the shortest possibility.
Daniel
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I was not able to express the problem correctly.
The following code should give you an idea what I am trying to accomplish.
The code is not working.
I am most concerned about the algorithm of the sub...
<html>
<title>Conquer_Parks_2</ti
<head>
<SCRIPT LANGUAGE="VBScript">
<!---
sub f1_onclick
set fred=window.document.Schwe
for i=0 to 5
if fred.elements(i).checked then
Radio_Value=fred.elements(
end if
next
for i= 6 to 9
Check_True=0
if fred.elements(i).checked=t
Check_True=Check_True+1
end if
if Check_True<=1 then
msgbox"Select at least one value"
exit sub
end if
if fred.elements(i).checked then
SName=SName + fred.elements(i).name + " "
end if
next
if fred.c1.value="default" then
msgbox"Select a value other than default"
exit sub
end if
select_d1=fred.d1.value
select_index=fred.d1.selec
oldchar_a=fred.d1.value
newchar_a=replace("oldchar
newchar_a=replace("newchar
newchar_a=replace("newchar
oldcharlen_a=len("oldchar_
newcharlen_a=len("newcharl
oldchar_b=fred.e1.value
newchar_b=replace("oldchar
newchar_b=replace("newchar
newchar_b=replace("newchar
oldcharlen_b=len("oldchar_
newcharlen_b=len("newcharl
document.clear
document.open
document.write"<html><body
document.write"<table width='80%' bgcolor='#ffffc0' border='1'><tr><td colspan='4'>" +chr(10)+chr(13)
document.write"<center><b>
document.write"<tr><td colspan='4' align='center'><b><h3>Radi
document.write"<tr><td>Nam
document.write"<td>Radio button checked at load time: Radio 1</td><td>Radio button checked by user: "&Radio_Value+chr(10)+chr(
document.write"</td</tr><t
document.write"<tr><td colspan='2'>Name of each checkbox: B1, B2, B3, B4</td><td colspan='2'>Selected Value: " &SName
document.write"</td></tr><
document.write"<tr><td>Nam
document.write"Third option, Third option<li> Fourth option, Fourth option<li>Fifth option, Fifth option<li>Sixth option, Sixth option</ul></td>" +chr(10)+chr(13)
document.write"<td>Index of the initial selection and its value: O, First one</td>"+chr(10)+chr(13)
document.write"<td>Index and value of initial selected by user: " &select_index" " &select_d1 +chr(10)+chr(13)
document.write"</td><tr><t
document.write"<tr><td>Nam
document.write"<td>User's entry and length of entry before editing: " &oldchar_a "and " &oldcharlen_a+chr(10)+chr(
document.write"</td><td>Us
document.write"</td></tr><
document.write"<tr><td>Nam
document.write"<td>User's entry and length of entry before editing: "&oldchar_b "and "&oldcharlen_b+chr(10)+chr
document.write"</td><td>Us
document.write"</td></tr><
end sub
--->
</script>
</head>
<body bgcolor="ffffc0">
<Form name="Schweinehund">
<center><b><h2>Assignment 2</h2></b></center><p><br>
<center><table border="0" width="80%" bgcolor="ffffc0">
<tr>
<td>RI<input type="radio" name="a1" checked value="Radio 1"></td>
<td>R2<input type="radio" name="a1" value="Radio 2"></td>
<td>R3<input type="radio" name="a1" value="Radio 3"></td>
<td>R4<input type="radio" name="a1" value="Radio 4"></td>
<td>R5<input type="radio" name="a1" value="Radio 5"></td>
<td>R6<input type="radio" name="a1" value="Radio 6"></td>
</tr><tr><td colspan="6"> </td>
</tr><tr><td colspan="6"><table border="0" width="100%" bgcolor="ffffc0"><tr>
<td>B1<input type="checkbox" name="b1 value="b1" ></td>
<td>B2<input type="checkbox" name="b2 value="b2" ></td>
<td>B3<input type="checkbox" name="b3 value="b3" ></td>
<td>B4<input type="checkbox" name="b4 value="b4" ></td></table></td></tr>
</tr><tr><td colspan="6"> </td>
</tr><tr>
<td colspan="6">
<center><select name="c1">
<option value="default" selected>First Option
<option value="Second option">Second Option
<option value="Third option">Third Option
<option value="Fourth option">Fourth Option
<option value="Fifth option">Fifth Option
<option value="Sixth option">Sixth Option
</center>
</select></td>
</tr><tr><td colspan="6"> </td>
</tr><tr>
<td colspan="6"><center><INPUT
</tr><tr><td colspan="6"> </td>
</tr><tr>
<td colspan="6"><center><texta
</tr><tr><td colspan="6"> </td>
</tr><tr>
<td colspan="6"><center><input
</tr>
</table></center>
</form>
</body>
</html>
Hi,
There are so many coding mistakes (Syntax) in your code. I have corrected all of them. You just need to paste the following code as it is into a HTML file and run it in a browser.
<html>
<title>Conquer_Parks_2</ti
<head>
<SCRIPT LANGUAGE="VBScript">
sub f1_onclick
Check_True=0
for i=0 to document.all("a1").length-
if Schweinehund.a1(i).checked
Radio_Value=Schweinehund.e
end if
next
for i= 0 to document.all("b1").length-
if Schweinehund.b1(i).checked
Check_True=Check_True+1
SName=SName + Schweinehund.b1(i).name + " "
end if
next
if Check_True=0 then
msgbox"Select at least one value"
exit sub
end if
if Schweinehund.c1.value="def
msgbox"Select a value other than default"
exit sub
end if
c1_value=Schweinehund.c1.o
oldchar_a=Schweinehund.d1.
if oldchar_a="" then
oldchar_a = "Blank"
newchar_a = "Blank"
else
newchar_a=replace("oldchar
newchar_a=replace("newchar
newchar_a=replace("newchar
end if
oldcharlen_a=len(oldchar_a
newcharlen_a=len(newchar_a
oldchar_b=Schweinehund.e1.
if oldchar_b="" then
oldchar_b = "Blank"
newchar_b = "Blank"
else
newchar_b=replace("oldchar
newchar_b=replace("newchar
newchar_b=replace("newchar
end if
oldcharlen_b=len(oldchar_b
newcharlen_b=len(newchar_b
document.clear
document.open
document.write"<html><body
document.write"<table width='80%' bgcolor='#ffffc0' border='1'><tr><td colspan='4'>"
document.write"<center><b>
document.write"<tr><td colspan='4' align='center'><b><h3>Radi
document.write"<tr><td>Nam
document.write"<td>Radio button checked at load time: Radio 1</td><td>Radio button checked by user: " & Radio_Value
document.write"</td</tr><t
document.write"<tr><td colspan='2'>Name of each checkbox: B1, B2, B3, B4</td><td colspan='2'>Selected Value: " & SName
document.write"</td></tr><
document.write"<tr><td>Nam
document.write"Third option, Third option<li> Fourth option, Fourth option<li>Fifth option, Fifth option<li>Sixth option, Sixth option</ul></td>"
document.write"<td>Index of the initial selection and its value: O, First one</td>"
document.write"<td>Index and value of initial selected by user: " & c1_value
document.write"</td><tr><t
document.write"<tr><td>Nam
document.write"<td>Users entry and length of entry before editing: " & oldchar_a & " and " & oldcharlen_a & "</td>"
document.write"</td><td>Us
document.write"</td></tr><
document.write"<tr><td>Nam
document.write"<td>User's entry and length of entry before editing: " & oldchar_b & " and " & oldcharlen_b
document.write"</td><td>Us
document.write"</td></tr><
end sub
</script>
</head>
<body bgcolor="ffffc0">
<Form name="Schweinehund" id="Schweinehund">
<center><b><h2>Assignment 2</h2></b></center>
<p><br>
<center><table border="0" width="80%" bgcolor="ffffc0">
<tr>
<td>RI<input type="radio" name="a1" checked value="Radio 1"></td>
<td>R2<input type="radio" name="a1" value="Radio 2"></td>
<td>R3<input type="radio" name="a1" value="Radio 3"></td>
<td>R4<input type="radio" name="a1" value="Radio 4"></td>
<td>R5<input type="radio" name="a1" value="Radio 5"></td>
<td>R6<input type="radio" name="a1" value="Radio 6"></td>
</tr>
<tr><td colspan="6"> </td></t
<tr>
<td colspan="6">
<table border="0" width="100%" bgcolor="ffffc0">
<tr>
<td>B1<input type="checkbox" name="b1" value="b1"></td>
<td>B2<input type="checkbox" name="b1" value="b2"></td>
<td>B3<input type="checkbox" name="b1" value="b3"></td>
<td>B4<input type="checkbox" name="b1" value="b4"></td>
</tr>
</table>
</td>
</tr>
<tr><td colspan="6"> </td></t
<tr>
<td colspan="6">
<center>
<select name="c1">
<option value="default" selected>First Option
<option value="Second option">Second Option
<option value="Third option">Third Option
<option value="Fourth option">Fourth Option
<option value="Fifth option">Fifth Option
<option value="Sixth option">Sixth Option
</select>
</center>
</td>
</tr>
<tr><td colspan="6"> </td></t
<tr>
<td colspan="6"><center><INPUT
</tr>
<tr><td colspan="6"> </td></t
<tr>
<td colspan="6"><center><texta
</tr><tr><td colspan="6"> </td>
</tr><tr>
<td colspan="6">
<center>
<input type="button" value="Edit and Report" name="f1" >
</td>
</tr>
</table></center>
</form>
</body>
</html>
Best of luck.
Regards,
Ramoji.
Business Accounts
Answer for Membership
by: RamojiPosted on 2002-10-15 at 13:47:44ID: 7335441
Hi,
h-1 .checked = false) then lue h then
Here is a sample HTML file with the vbscript code you want.
<html>
<script language=vbscript>
sub fnCheck()
dim arr(4)
dim count
for i=0 to document.all("chk1").lengt
if(document.all("chk1")(i)
count = count + 1
else
arr(i) = document.all("chk1")(i).va
msgbox arr(i)
end if
next
if count = document.all("chk1").lengt
msgbox "Atleast One Country Should be Selected"
end if
end sub
</script>
<body >
India<input type=checkbox id=chk1 name=chk1 value="India">
America<input type=checkbox id=chk1 name=chk1 value="America">
England<input type=checkbox id=chk1 name=chk1 value="England">
Russia<input type=checkbox id=chk1 name=chk1 value="Russia">
<input type=button value="Edit" onclick="fnCheck()">
</body>
</html>
Best of luck.
Regards,
Ramoji.