Quote:
Originally Posted by DaveyErwin
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>  
 
<a href="index.php" class="links" style="color:white">Web</a>    
<a href="image.php" class="links">Images</a>    
<a href="videos.php" class="links">Videos</a>    
<a href="adult videos.php" class="links">Adult Videos</a>    
</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>