Recent Widgets


Register for DashboardWidgets

Recent Forums Posts

Partners


iCompositions

MacDesktops.net

RSS Showcase
RSS Comments
RSS Forums

This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies. Posted in: Widget Design

Javascript Noob-Search Engine widget help

Author Message
Hendo



Joined: 10 Sep 2006
Posts: 3
Location: Barrie, Ontario

Posted: Sun Sep 10, 2006 - 12:38 pm    Post subject: Javascript Noob-Search Engine widget help Reply with quote

I am really new to javascript and to try and learn it I have decided to make a basic widget with a search field and a drop down menu with a list of places to search.
So far I only have the google code in, but it doesnt work. Here is the javascript
Code:
function changeEngine(elem)
{   
   var engine = document.getElementById('select').focus();
   
   switch( parseInt(elem.options[elem.selectedIndex].value) )               // find out which option was chosen
   {
      case 1:                            // if option #1 ("Google")   
         engine.innerText="Google";
window.onfocus = function () {
   document.getElementById('search-input').focus();
}

      function search (input)
{
   var value = input.value;
   if (value.length > 0)
   {
      value = encodeURIComponent (value);
      var url = "http://www.google.com/search?q=" + value + "&ie=UTF-8&oe=UTF-8";
      if (window.widget)
         widget.openURL (url);
   }
}

function keydown (event, input)
{
   if (event.keyCode == 13) // enter or return
   {
      search (input);
   }
}         break;
      


and here is the HTML
Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
        "http://www.w3.org/TR/html4/strict.dtd">
<head>
   <meta http-equiv="content-type" content="text/html; charset=utf-8">
   <style type="text/css" title="AppleStyle">
      @import "MySearch.css";
   </style>
   <script type='text/javascript' src='MySearch.js' charset='utf-8'></script>
</head>
<body>
      <img src='default.png'></img>
      <input type='search' id='search-input' onkeydown='keydown(event, this);' results='0'></input><select id='select' onchange='changeEngine(this);'>
<option value=1>Google</option>
<option value=2>Yahoo!</option>
<option value=3>Lycos</option>
<option value=4>AltaVista</option>
<option value=5>Wikipedia</option>
<option value=6>MacUpdate</option>
<option value=7>Version Tracker</option>
<option value=8>Softpedia</option>
</select>
</body>
</html>


When I hit enter nothing happens Sad
View user's profile Send private message Send e-mail Visit poster's website Widgets
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.

 
Powered by phpBB © 2001, 2002 phpBB Group