View Single Post
Old 09-21-2012, 08:41 PM   PM User | #6
bigcasey123
New Coder

 
Join Date: Feb 2012
Posts: 95
Thanks: 1
Thanked 5 Times in 4 Posts
bigcasey123 is an unknown quantity at this point
Quote:
Originally Posted by DaveyErwin View Post
among other problems
you may have, this code
must not be executed before
window.onload(or body.onload)
has fired, also you must
have a form element
with the name (not id)
"engine"
This code isn't executed before window.onload (or body.onload) and i had a name "engine" not id. Here is my body code

Code:
<body>
 
 
 
 
 
 <div id="header">
 <b>  &nbsp
      &nbsp
 <a href="index.php" class="links" style="color:white">Web</a> &nbsp &nbsp
 <a href="image.php" class="links">Images</a> &nbsp &nbsp
 <a href="videos.php" class="links">Videos</a> &nbsp &nbsp
 <a href="adult videos.php" class="links">Adult Videos</a> &nbsp &nbsp
 </b>
 </div>
 
 
 <img id="theImage" name="theImage" />
 
<form id="theForm" onSubmit="return doSearch()" name="theForm">
<input name="search" id="searchbox"/>
<br/>
Use what engine:
    <select name="engine">
	<option> Choose one</option>
    <option value="google">Google</option>
    <option value="yahoo">Yahoo</option>
    <option value="ask">ask</option>
	<option value="bing">bing</option>
    </select>
<br/>
<br />
<center><input type="button" value="Search!" name="doit"/></center>
</form>

<script type="text/javascript">
(function( )
  {
  function doGoogle( searchFor ) { this.location.href="https://www.google.com/search?q="+searchFor; }
  function doYahoo( searchFor ) { this.location.href="http://search.yahoo.com/search?p="+searchFor; }
  function doBing( searchFor ) { this.location.href="http://www.bing.com/search?q="+searchFor; }
  function doAsk( searchFor ) { this.location.href="http://www.ask.com/web?q="+searchFor; }
      var choices = {
          "google" : { "logo" : "images/google.png", "code" : doGoogle },
          "yahoo" : { "logo" : "images/yahoo.png", "code" : doYahoo },
		  "bing" : { "logo" : "images/bing.png", "code" : doBing },
		  "ask" : { "logo" : "images/ask.png", "code" : doAsk },
		 
      }
	  
	  var form = document.getElementById("theForm");
      var engineCode = null;

      form.engine.onchange = function( )
      {
          var choice = this.value;
          if ( choice == "" ) return; // "choose one" selected?
          document.getElementById("theImage").src = choices[choice].logo;   
          engineCode = choices[choice].code;
     }
     
     form.doit.onclick = function( ) 
     {
         if ( engineCode != null )
         {
            engineCode( form.search.value );
         }
     }
  }
)( ); // self-invoke anonymous function
</script>

 </body>
bigcasey123 is offline   Reply With Quote