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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Problem with Checkbox Code 1

Status
Not open for further replies.

compuv

MIS
Mar 16, 2002
10
GB
Boomerang very kindly gave me the code below to call up a separate web page depending on which combination of checkboxes are ticked. Unfortunately I can't get it to work. I've set up a test page at I've been over the code with a fine toothcomb but can't see what I'm doing wrong. Ideally I'd like the new page to open in the same window without opening a separate one. Any help would be greatly appreciated as my colleague and I spent hours on this and got nowhere!

<html>
<head>
</head>

<body>

<script language=&quot;javascript&quot;>
function opensite()
{
var endvalue = &quot;&quot;;
var DM = document.MyForm1;
var NrCbs = DM.cb1.length;
var a = &quot;google.com&quot;;
var b = &quot;yahoo.com&quot;;
var c = &quot;CNN.com&quot;;
var ab= &quot;microsoft.com&quot;;
var ac= &quot;netscape.com&quot;;
var bc = &quot;W3.org&quot;;
var abc = &quot;tek-tips.com&quot;;
var preURL = &quot;
for (ia = parseInt(0); ia < NrCbs; ia++)
{
if (DM.cb1[ia].checked)
endvalue = endvalue + DM.cb1[ia].value;
}

defURL = eval(&quot;'&quot; + preURL + eval(endvalue) + &quot;'&quot;);

if (!endvalue == &quot;&quot;)
{
window.open(defURL, 'windowname3','toolbar=yes, location=yes,
directories=yes, status=yes, menubar=yes, resizable=yes,
scrollbars=yes, top=0, left=0, height=600, width=800');
}
else
{
alert(&quot;no checkboxes are selected&quot;)
}
}
</script>

<form name=&quot;MyForm1&quot;>
a: <INPUT TYPE=&quot;checkbox&quot; value=&quot;a&quot; name=cb1>
b: <INPUT TYPE=&quot;checkbox&quot; value=&quot;b&quot; name=cb1>
c: <INPUT TYPE=&quot;checkbox&quot; value=&quot;c&quot; name=cb1>
<br>
<input type=&quot;submit&quot; value=&quot;go to the site&quot; name=&quot;submit777&quot;
ONCLICK=&quot;opensite()&quot;>
</form>

</body>
</html>
 
Well my editor is telling me there is an error but not what that error is! :(
I presume the form is missing an &quot;action&quot; but thats as far as I can advise you, sorry.

I'm sure Boomerang will spot the error.



É

endamcg-logo1b.gif

 
Hi Dave,

I answered the &quot;error&quot; in your code in the original post.

To open the new page in the same window, do the following:

change window.open(defURL, 'windowname3','toolbar=yes, location=yes,
directories=yes, status=yes, menubar=yes, resizable=yes,
scrollbars=yes, top=0, left=0, height=600, width=800');
to this.location.href = defURL;

change <form name=&quot;MyForm1&quot;> to <form name=&quot;MyForm1&quot; action=&quot;javascript:eek:pensite()&quot;>

I hope you get it on to work now!! And don't forget that all the effort you did is not for nothing. You learnt !!

Erik

<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Maybe my post was a bit confusing? I tried to say:

To open the new page in the same window, do the following:

1)change
window.open(defURL, 'windowname3','toolbar=yes, location=yes,
directories=yes, status=yes, menubar=yes, resizable=yes,
scrollbars=yes, top=0, left=0, height=600, width=800');


to
this.location.href = defURL;

2)change
<form name=&quot;MyForm1&quot;>

to
<form name=&quot;MyForm1&quot; action=&quot;javascript:eek:pensite()&quot;>

Please let me know if this works, Dave?
Erik
<!-- My sport: Boomerang throwing !!
This year I will participate at the World Championships in Germany. (!! Many Happy Returns !! -->
 
Your original post was fine, Boomerang -I understood it perfectly. I still can't get it to work though and this time it's giving me runtime errors both when the page loads and when I click the button! This is so frustrating as we must be so close to the solution. Many thanks for your help.


Dave
 
Bingo!!! See if you can spot the delberate mistake in the line:
var preURL = &quot;
It appears to work perfectly now this has been changed to:
var preURL = &quot;
Well done, Boomerang - you're a genius!! Many thanks.

Dave
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top