...

View Full Version : Help with form leading to urls in active window and new windows



maltrecho
02-19-2003, 10:08 PM
I've got a problem with the code I'm using and I hope any of you can help me.

I've got a form with some check-boxes and a submit button. Depending on the box that is checked, the user should be leaded to a new browser window or to an url in the same window.

The javascript is in a *.js file, and the code is like this:

------------------------------------------------------------------------------------
function Select(){

if(document.form.CHECKBOX1.checked==true)window.open('http://THEURL1/'+document.form.text.value);

if(document.form.CHECKBOX2.checked==true)window.open('http://THEURL1/'+document.form.text.value);

}
------------------------------------------------------------------------------------

So, this way if both check-boxex are checked, the active window will go to an url, and a new window will lead to the second url.

I don't know if the problem is with the window.open (I thought it should be self.open). And I also tried to add a '_top' or '_same' after the +document.form.text.value. I can't make it work. Any suggestion?. Thanks in advance.

glenngv
02-20-2003, 03:45 AM
to open to the same window:

window.open(url,"_self");

or:

location.href = url;

maltrecho
02-20-2003, 12:37 PM
with the script I'm using it doesn't work. I cannot write:

window.open
( ' http://THEURL1/ ' +document.form.text.value , " _self " );

nor:

window.open
( ' http://THEURL1/ ' +document.form.text.value , ' _self ' );

should be something like:

window.open
( " ' http://THEURL1/ '+document.form.text.value " , " _self ");

but that doesn't work. I don't know how o use the " and the '.

TheMenace
02-20-2003, 12:54 PM
[code]
function Select(){

if(document.form.CHECKBOX1.checked==true) {

window.location('http://THEURL1/'+document.form.text.value);

}

if(document.form.CHECKBOX2.checked==true) {

window.location('http://THEURL1/'+document.form.text.value);

}

}

maltrecho
02-20-2003, 03:03 PM
Doesn't work either. Thanks for your posts.

maltrecho
02-20-2003, 03:07 PM
actually that is the code I'm using ( with all the {} ). Tke first one was simplified.

maltrecho
02-20-2003, 03:41 PM
YOU CAN CHECK THE CODE IN THIS FILE!!!
Please help me.

maltrecho
02-20-2003, 10:59 PM
Can anybody help me?

glenngv
02-21-2003, 01:41 AM
as i've said you before...

function Search(){
if
(document.form.google.checked==true) {
window.open('http://www.google.com/search?q='+document.form.text.value,"_self");
//or simply this:
//location.href='http://www.google.com/search?q='+document.form.text.value;
}
if
(document.form.googleimages.checked==true) {
window.open('http://images.google.com/images?q='+document.form.text.value);
}
}

maltrecho
02-21-2003, 02:18 AM
I tried that in the file I attached and nothing, the first check-box doesn't work yet, it goes nowhere. I tried both options. Is it working in your PC? If that's so, could you attach your file?. Perhaps that only works once on-line (but I think that is stupit).

I don't know, I've been here all day sarching for solutions and I can't any more. Thanks Glenngv and others.

glenngv
02-21-2003, 03:07 AM
you are using a submit button and <form onSubmit="Search()">
so the form gets submitted everytime the submit button is clicked.

you should have made it like <form onSubmit="return Search()">
and then put return false; at the end of the Search() function to cancel submission

or to simplify it, remove the onsubmit handler and also the return false in the function then make your button:
<input type="button" value="Find It!" onclick="Search()">

maltrecho
02-21-2003, 04:19 AM
Hey Glenngv I owe you a big one. The world would be better with more people like you. All the best 4 u.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum