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

Search - Open New Window

Status
Not open for further replies.

AKS44

Programmer
Feb 7, 2006
20
0
0
US
Hello, I'm trying to get the following script to open in a new window when a user clicks on one of the buttons. Here it is, any help is greatly appriceated.

***********

String.prototype.trim = function()
{
return this.replace(/^\s*|\s*$/g,'');
}
function ProcessInput(e)
{
if (window.event) // IE
keyNum = e.keyCode;else if (e.which) // Netscape/Firefox/Opera
keyNum = e.which; if (keyNum == 13)
{
e.returnValue = false;e.cancelBubble = true;
DoKeywordSearch('KW');
return false;
}
return true;
}
function DoBrowseSearch(strBy)
{
if (document.getElementById('textboxTerm').value.trim() != '')
{
var strURL = 'window.location = strURL + "&type=Browse&Page=0&by=" + strBy + "&term=" + escape (document.getElementById('textboxTerm').value);
}
else document.getElementById('textboxTerm').focus();
}
function DoKeywordSearch(strBy)
{
if (document.getElementById('textboxTerm').value.trim() != '')
{
var strURL = 'window.location = strURL + "&type=Keyword&limit=TOM=*&sort=RELEVENCE&Page=0&by=" + strBy + "&term=" + escape(document.getElementById('textboxTerm').value);
}
else document.getElementById('textboxTerm').focus();
}
</script>
<table> <tr> <td>Search for: </td> <td>
<input type=text id=textboxTerm size=45 onkeypress="return ProcessInput(event)" />
</td> </tr> <tr> <td>Search by: </td> <td>
<input type=button value="Title" onclick="DoBrowseSearch('TI');" />
<input type=button title="Lastname, First" value="Author" onclick="DoBrowseSearch('AU');" />
<input type=button value="Subject" onclick="DoKeywordSearch('SU');" />
<input type=button value="Series" onclick="DoBrowseSearch('SE');" />
<input type=button value="Keyword" onclick="DoKeywordSearch('KW')" />
</td> </tr> </table>
<script language="javascript">
document.getElementById('textboxTerm').focus();
 
Ok... I figured out the window.open but now, when the new page opens the page behind (original search page) redirects to a 404 and in the address bar it has [object]&type=Browse&Page=0&by=TI&term=search

Again any help is greatly appriceated.
 
Ok... I figured out the window.open but now, when the new page opens the page behind (original search page) redirects to a 404 and in the address bar it has [object]&type=Browse&Page=0&by=TI&term=search

I added window.open to the following line of code from my previous post.

var strURL = window.open ('window.location = strURL + "&type=Keyword&limit=TOM=*&sort=RELEVENCE&Page=0&by=" + strBy + "&term=" + escape(document.getElementById('textboxTerm').value);

Again any help is greatly appriceated.
 
Ok I got it... Thanks in advance to those how view this post. Here is the final source.

/////////////////////////////////

{
return this.replace(/^\s*|\s*$/g,'');
}
function ProcessInput(e)
{
if (window.event) // IE
keyNum = e.keyCode;else if (e.which) // Netscape/Firefox/Opera
keyNum = e.which; if (keyNum == 13)
{
e.returnValue = false;e.cancelBubble = true;
DoKeywordSearch('KW');
return false;
}
return true;
}
function DoBrowseSearch(strBy)
{
if (document.getElementById('textboxTerm').value.trim() != '')
{
var strURL = window.open ('window.open = strURL + "&type=Browse&Page=0&by=" + strBy + "&term=" + escape (document.getElementById('textboxTerm').value);
}
else document.getElementById('textboxTerm').focus();
}
function DoKeywordSearch(strBy)
{
if (document.getElementById('textboxTerm').value.trim() != '')
{
var strURL = window.open ('window.open = strURL + "&type=Keyword&limit=TOM=*&sort=RELEVENCE&Page=0&by=" + strBy + "&term=" + escape(document.getElementById('textboxTerm').value);
}
else document.getElementById('textboxTerm').focus();
}
</script>
<table> <tr> <td>Search for: </td> <td>
<input type=text id=textboxTerm size=45 onkeypress="return ProcessInput(event)" />
</td> </tr> <tr> <td>Search by: </td> <td>
<input type=button value="Title" onclick="DoBrowseSearch('TI');" />
<input type=button title="Lastname, First" value="Author" onclick="DoBrowseSearch('AU');" />
<input type=button value="Subject" onclick="DoKeywordSearch('SU');" />
<input type=button value="Series" onclick="DoBrowseSearch('SE');" />
<input type=button value="Keyword" onclick="DoKeywordSearch('KW')" />
</td> </tr> </table>
<script language="javascript">
document.getElementById('textboxTerm').focus();
 
Ooops... I jumped the gun.. This still doesn't work as it should. It now opens a new window the first time, but returns a script error on second run. It also doesn't pass the string information on to the next page.
 
Some errors in red:
Code:
function DoBrowseSearch(strBy)
{ 
if (document.getElementById('textboxTerm').value.trim() != '')
{
var strURL = window.open ('[URL unfurl="true"]http://domain.com/search/browse.aspx?ctx=1.1033.0.0.6');[/URL] 
[red]window.open = strURL + "&type=Browse&Page=0&by=" + strBy + "&term=" + escape (document.getElementById('textboxTerm').value);[/red]
}
else document.getElementById('textboxTerm').focus();
}
function DoKeywordSearch(strBy)
{ 
if (document.getElementById('textboxTerm').value.trim() != '')
{ 
var strURL = window.open ('[URL unfurl="true"]http://domain.com/search/searchresults.aspx?ctx=1.1033.0.0.6');[/URL]
[red]window.open = strURL + "&type=Keyword&limit=TOM=*&sort=RELEVENCE&Page=0&by=" + strBy + "&term=" + escape(document.getElementById('textboxTerm').value);[/red]
}
else document.getElementById('textboxTerm').focus();
}

Lee
 
Thanks Lee,

I am aware that the error is coming from those lines. I changed window.open to window.location for those lines and it still does not work properly.

Could you provide some direction as to why versus pointing out the erroneous lines without a solution?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top