I haven't used javascript for a while, but I didn't think I'd forget as much as I did... This simple google search isn't picking up my textbox variable. Where did I mess up?


Code:

function search()
{
   var searchTerm;
   searchTerm = document.searchform.tehsearchzors;
   window.location="http://www.google.com/search?hl=en&q=" + searchTerm + "&btnG=Google+Search";
}


<form name="searchform">
<input type="text" name="tehsearchzors">
<input type="button" value = "Search" onClick="search()">
</form>
bad habits Wink

Quote:

function search(int i)
{
var searchTerm;
searchTerm = document.getElementByID('searchform').tehsearchzors;
window.location="http://www.google.com/search?hl=en&q=" + searchTerm + "&btnG=Google+Search";
}


<form id="searchform" action="#" method="GET">
<input type="text" name="tehsearchzors">
<input type="button" value = "Search" onClick="search(0)">
</form>
Seconded. Make sure it's cross-browser. Smile
err....
elfprince13 wrote:
bad habits Wink

Quote:

function search(int i)
{
var searchTerm;
searchTerm = document.getElementByID('searchform').tehsearchzors;
window.location="http://www.google.com/search?hl=en&q=" + searchTerm + "&btnG=Google+Search";
}


<form id="searchform" action="#" method="GET">
<input type="text" name="tehsearchzors" />
<input type="button" value = "Search" onClick="search(0)" />
</form>

[edit] why not just do this?
<form action="http://www.google.com/search" method="GET">
<input type="hidden" name="hl" value="en" />
<input type="q" type="text" />
<input type="submit" name="btnG" value="Google Search" />
</form>
I just tried all 3 of those methods, and I can't get any of them to work. The last one at least goes to google, but it doesn't search for what's in the box.
<_< typo


Code:
<form action="http://www.google.com/search" method="GET">
<input type="hidden" name="hl" value="en" />
<input type="text" name="q"  />
<input type="submit" name="btnG" value="Google Search" />
</form>


btw, the javascript error console is always nice Wink
Oh, sweet, that works great! I was using javascript because I wanted to search when someone clicked on a picture. I really just had the button to check my search script. I haven't really done much with html. Is using a picture still possible with this method?

EDIT: Actually, to make it clear, my plan is to have a text box to type in a search term, then you can click on a picture for either google, yahoo, wikipedia, dictionary.com, etc. Or maybe a dropdown menu would be better...
You can use images for buttons with HTML. I don't remember HOW, but you can Smile
input type=image

or just add an onClick to a normal image

[edit]

or

<button><img src="..."></button>

[edit2]

Code:

<form action="http://www.google.com/search" method="GET">
<input type="hidden" name="hl" value="en" />
<input type="text" name="q"  />
<button type="submit" name="btnG" value="Google Search"><img src="http://rancidmoose.5gigs.com/dinocomplete.png"/></button>
</form>


should do the trick (I havent tested it, but something along those ligns--its best to avoid JS when possible)
I was looking for a way to just use one textbox, but be able to choose which search engine you use. That way would involve a textbox for every engine, wouldn't it?
<a href="#" onClick="javascript:document.forms.[formname].submit;"><img...></a>
KermMartian wrote:
<a href="#" onClick="javascript:document.forms.[formname].submit;"><img...></a>


Ooohhhh, I think I get it. Each picture goes as a separate link. Then each link generates its search term from the universal text box. Sounds good. Smile

I'll try it out tomorrow in CS.
foamy3 wrote:
I was looking for a way to just use one textbox, but be able to choose which search engine you use. That way would involve a textbox for every engine, wouldn't it?


have a javascript coded dropdown menu, and give the textbox an id= value. then just use javascript to change the source of the image and the name (not id) of the textbox when a new engine is selected
foamy3 wrote:
KermMartian wrote:
<a href="#" onClick="javascript:document.forms.[formname].submit;"><img...></a>


Ooohhhh, I think I get it. Each picture goes as a separate link. Then each link generates its search term from the universal text box. Sounds good. Smile

I'll try it out tomorrow in CS.
Sounds good to me! You can do some Javascript-fu, or you can use a PHP handler to sort it out.
I don't think anyone in my class knows PHP. Hell, I doubt we even have it installed on our server Rolling Eyes
foamy3 wrote:
I don't think anyone in my class knows PHP. Hell, I doubt we even have it installed on our server Rolling Eyes
Meh, make a javascript onSubmit handler then/
I just got this baby cooked up. I still need to add a changing logo on top to go with the drop-down.


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";
   if(document.searchform.chooseEngine.value=="yahoo")
      window.location="http://search.yahoo.com/search?p=" + searchArg + "&fr=yfp-t-501&toggle=1&cop=mss&ei=UTF-8";
   if(document.searchform.chooseEngine.value=="dictionary")
      window.location="http://dictionary.reference.com/browse/" + searchArg;

}


<form name="searchform">
<select NAME="chooseEngine">
<option VALUE="google" SELECTED> Google.com
<option VALUE="yahoo" SELECTED> Yahoo.com
<option VALUE="dictionary" SELECTED> Dictionary.com
</select>
<input type="text" name="searchterm">
<input type="button" value = "Search" onClick="search()">
</form>
  
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