The code for an internet search thing looks like this

Code:
function search()
{
   var searchArg;
   searchArg = document.searchform.searchterm.value;
   if(document.searchform.chooseEngine.value=="google")
      window.location="http://www.google.com/search?hl=en&q=" + searchArg + "&btnG=Google+Search";


The form looks like this

Code:


<form name="searchform">
<select NAME="chooseEngine">
<option VALUE="google" SELECTED> Google.com
</select>
<br><input type="text" name="searchterm"><br>
<input type="button" value = "Search" onClick="search()">
</form>


People have a bad habit of just hitting enter instead of the button. Is there any way to make the enter button run the search function? Right now, hitting enter just refreshes the page.
Wow... no one? Don't get me wrong, I'm not complaining that I didn't get an answer. I'm just surprised. I figured the amount of geekness in this forum would have the question answered before I finished asking Very Happy
Try a google search next time, please (first result): http://www.cs.tut.fi/~jkorpela/forms/enter.html
Kllrnohj wrote:
Try a google search next time, please (first result): http://www.cs.tut.fi/~jkorpela/forms/enter.html
I was going to suggest that, but I didn't have the time to post a JFGI notice. Razz
I googled it a lot. I only found stuff to submit on enter. I just want it to call a function on enter. I don't really know how submit forms work.

Code:

function entsub(searchform) {
  if (window.event && window.event.keyCode == 13)
    searchform.search();
  else
    return true;}

I don't know what the window.event thing does. Do you think the code above would work? (I can't test until I get to school tomorrow)
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 1
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement