...

View Full Version : need script go to web page depending on checkbox selected



cwebmaster
06-13-2008, 05:16 PM
Hi

I am looking for help on a script that has a row of checkboxes, A user can then select 1 or more checkboxes, and then have a button, when clicked allows the user to go the the web page, depending on which checkbox was
selected.

Thanks Dave

binaryWeapon
06-13-2008, 06:36 PM
Javascript checkbox object tutorial: http://www.javascriptkit.com/jsref/checkbox.shtml
Javascript if tutorial: http://www.w3schools.com/JS/js_if_else.asp
To take the browser to a different page use document.location=<url>

Basically call a function when you click the button. The function checks to see what checkboxes are checked, and takes it to a certain page accordingly.

Philip M
06-13-2008, 06:49 PM
Hi

I am looking for help on a script that has a row of checkboxes, A user can then select 1 or more checkboxes, and then have a button, when clicked allows the user to go the the web page, depending on which checkbox was
selected.

Thanks Dave

That does not make much sense - how can that work if the user selects more than one checkbox? You want to use radio buttons.


<form name = "myform">
PAGE 1<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page1.html"><br>
PAGE 2<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page2.html"><br>
PAGE 3<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page3.html"><br>
PAGE 4<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page4,html"><br>
<input type = "button" name = "but1" value = "Click to go to selected page" onclick = "goPage()">
</form>

<script type = "text/javascript">
function goPage() {
var selected = 0;
for (var i = 0; i < document.myform.rad1.length; i++) {
if (document.myform.rad1[i].checked) {
selected = 1;
window.location = document.myform.rad1[i].value;
}
}
if (selected == 0) {
alert ("You must select a radio button!");
}
}

</script>

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

cwebmaster
06-13-2008, 07:07 PM
That does not make much sense - how can that work if the user selects more than one checkbox? You want to use radio buttons.


<form name = "myform">
PAGE 1<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page1.html"><br>
PAGE 2<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page2.html"><br>
PAGE 3<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page3.html"><br>
PAGE 4<input type = "radio" name = "rad1" value = "http://www.yourdomain.com/page4,html"><br>
<input type = "button" name = "but1" value = "Click to go to selected page" onclick = "goPage()">
</form>

<script type = "text/javascript">
function goPage() {
var selected = 0;
for (var i = 0; i < document.myform.rad1.length; i++) {
if (document.myform.rad1[i].checked) {
selected = 1;
window.location = document.myform.rad1[i].value;
}
}
if (selected == 0) {
alert ("You must select a radio button!");
}
}

</script>

All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.
This is what I am trying to do with multiple checkboxes, thanks

http://www.horizonindustriesltd.com/s/QwikReport.asp



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum