Warning

 

Close
Confirm Action

Are you sure you wish to do this?

Cancel Confirm
AR15.COM
11/7/2010 2:29:58 PM EDT
I'm working on a mockup of a website for usability testing. One of the "functions" is a search, done with the standard textbox/button. I just have to fake this functionality for the sake of testing how easy the page is to use. I can't get it to work at all.

This should be simple––if the user enters the word "perkscard" in the box, go to one page, otherwise go to the other page. I keep getting stuff tacked on to the end of the URL though, when I run it locally.

Some code:

<form name="SearchForm" action="">
           <div id="searchBackground">
           <input type="text" id="searchBoxText" name="q" />
           <input type="image" name="searchButton" src="images/button_search.png" onmouseover="src='images/button_search_over.png'"  
onmouseout="src='images/button_search.png'" alt="Search" title="Search" onclick="searchResult"/>
           </div>
           </form>


<script language="javascript" type="text/javascript">
function searchResult () {
var textbox = document.getElementById("searchBoxText");
var searchString = textbox.value;
if (searchString.toLowerCase()=="perkscard") {
window.location.replace("perkscard.html");
}
else {
window.location=("noresults.html");
}
//alert("I don't know why I have to do this to make the Java script work, Please Ignore");
}
</script>


It's not consistent because I've been messing with it for hours. I really need to get this figured out. Any ideas?
11/7/2010 2:43:11 PM EDT
[#1]
Try this out.


<form name="SearchForm" action="">
<div id="searchBackground">
<input type="text" id="searchBoxText" name="q" />
<input type="image" name="searchButton" src="images/button_search.png" onmouseover="src='images/button_search_over.png'" onmouseout="src='images/button_search.png'" alt="Search" title="Search" onclick="searchResult"/>
</div>
</form>

<script type="text/javascript">
<!––
function searchResult () {
var goToPage = (document.getElementById('searchBoxText').value.toLowerCase() == 'perkscard') ? "perkscard.html" : "noresults.html";
window.location = goToPage;
\\ ––>
</script>
11/7/2010 2:44:39 PM EDT
[#2]
Remove the parenthesis from window.location.  



e.g. window.location = "site"
11/7/2010 2:47:29 PM EDT
[#3]
return false in the onclick event for the button. i.e., onclick="searchResult(); return false;"

ETA: On second thought, remove the onclick event and add onsubmit="searchResult(); return false;" to the form element.
11/7/2010 2:53:55 PM EDT
[#4]
No luck with any of the above. It keeps adding a querystring to the end of the url, i.e. when I click I get the url + ?q=perkscard
11/7/2010 2:55:48 PM EDT
[#5]
Quoted:
No luck with any of the above. It keeps adding a querystring to the end of the url, i.e. when I click I get the url + ?q=perkscard


The <input type="image"> acts as a submit button for the parent <form>. Add an onsubmit event handler to the <form> and return false after calling your function to prevent the default onsubmit handler from being fired.
11/7/2010 2:56:08 PM EDT
[#6]
nvm
11/7/2010 3:00:37 PM EDT
[#7]
Quoted:
Quoted:
No luck with any of the above. It keeps adding a querystring to the end of the url, i.e. when I click I get the url + ?q=perkscard


The <input type="image"> acts as a submit button for the parent <form>. Add an onsubmit event handler to the <form> and return false after calling your function to prevent the default onsubmit handler from being fired.


Did this––no luck.

One observation––I'm on my local drive. The path to the page is with backslashes i.e. "C:\Documents and Settings\.....". The window after clicking is "file:///C:/Documents and Settings/...."

It almost looks like its messing up the path


11/7/2010 3:10:36 PM EDT
[#8]
Quoted:
Quoted:
Quoted:
No luck with any of the above. It keeps adding a querystring to the end of the url, i.e. when I click I get the url + ?q=perkscard


The <input type="image"> acts as a submit button for the parent <form>. Add an onsubmit event handler to the <form> and return false after calling your function to prevent the default onsubmit handler from being fired.


Did this––no luck.

One observation––I'm on my local drive. The path to the page is with backslashes i.e. "C:\Documents and Settings\.....". The window after clicking is "file:///C:/Documents and Settings/...."

It almost looks like its messing up the path




In my case it's bringing up noresults.html when I have nothing in the box, but when I hit back, the query string is there. It'll go away if you set the form method to post.
11/7/2010 3:41:58 PM EDT
[#9]
Well, now it's working OK in Chrome and Firefox, just not in IE 8. That could be me though––IE has been doing some wierd stuff on my machine.

I think we can make this work. Thanks for the help.