Link to home
Start Free TrialLog in
Avatar of jianxin9
jianxin9

asked on

Opening form results in new browser window

I have a form that allows me to search, etc. but I can't figure out how to open the form results in another browser.  I've inserted target="_blank" but this doesn't seem to be working.
<script language="JavaScript">
 
function startSearch(){
searchString = document.searchForm.searchText.value; 
if(searchString != ""){
searchEngine = document.searchForm.whichEngine.selectedIndex + 1;
finalSearchString = "";
 
if(searchEngine == 1){
finalSearchString = "http://search.ebscohost.com/login.aspx?direct=true&bquery=" + searchString + "&db=a9h";
}
if(searchEngine == 2){
finalSearchString = "http://search.ebscohost.com/login.aspx?direct=true&bquery=" + searchString + "&db=lih";
}
if(searchEngine == 3){
finalSearchString = "http://www.jstor.org/action/doBasicSearch?Query=" + searchString + "&x=0&y=0";
}
if(searchEngine == 4){
finalSearchString = "http://search.ebscohost.com/login.aspx?direct=true&bquery=" + searchString + "&db=f5h";
}
if(searchEngine == 5){
finalSearchString = "http://www.springerlink.com/content/?k=" + searchString + "";
}
location.href = finalSearchString;
}
}
 
 
// -->
</script>
 
<basefont face="Verdana, Arial, sans-serif">
 
<form name="searchForm" target="_blank">
 
 
 
 
 
<input type="text"  size="17" name="searchText" value="Database Search" onFocus="clearText(this)">
 
<select style="background: dddddd" name="whichEngine" onchange="tryLink(this)">
<option selected>Academic Search Complete</option>
<option>LISTA</option>
<option>JSTOR</option>
<option>Masterfile Premier</option>
<option>Springerlink</option>
 
 
</select>
 
<input type="button" value="Search" onClick="startSearch()">
 
</select> </form>

Open in new window

Avatar of Zvonko
Zvonko
Flag of North Macedonia image

This line is your problem:

location.href = finalSearchString;


Change that line to this  two lines:

document.searchForm.action = finalSearchString;
document.searchForm.target = "ResultWindow"


ASKER CERTIFIED SOLUTION
Avatar of neeraj523
neeraj523
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My line with the form.target does the same as window.open() but works also with popup blockers.
@Zvonko.. i guess you missed the fact that 'Search' button is not submitting the form, instead it is just calling Javascript function. So changing the action and target attributes will do nothing till form gets submitted.. which is not the case in this situation..
Yes, I missed that form is not submitted at all.