Implement search Engine Using JavaScript

Chikul
Posted by Chikul under JavaScript category on | Views : 3009
<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Implement search Engine Using JavaScript</title>
<script type="text/javascript" language="javascript">

function fnSearch()
{
var Flag = 0;

var Query = document.getElementById('Searchtxt').value;
if (Query == "")
{
alert("Please enter a search text");
return;
}

if (document.getElementById('Google').checked==true)
{
var Flag = 1;
var Engine = document.getElementById('Google').value;
var locName = "http://www.google.com/search?hl=en&q=";
location.href = (locName + Query)
}

if (document.getElementById('Yahoo').checked==true)
{
var Flag = 1;
var Engine = document.getElementById('Yahoo').value;
var locName = "http://search.yahoo.com/search?p=";
location.href = (locName + Query)
}

if (document.getElementById('Both').checked==true)
{
var Flag = 1;
var Engine = document.getElementById('Both').value;

var searchPage = "<HTML>";
searchPage += "\n";
searchPage += "<FRAMESET ROWS=\"50%,50%\">";
searchPage += "\n";
searchPage += "<FRAME SRC=\"http://www.google.com/search?hl=en&q=" + Query + "\">";
searchPage += "\n";
searchPage += "<FRAME SRC=\"http://search.yahoo.com/search?p=" + Query + "\">";
searchPage += "\n";
searchPage += "</FRAMESET>";
searchPage += "\n";
searchPage += "</HTML>";
document.write(searchPage);
}

if (Flag == 0)
{
alert("Please select a search engine");
}
}
</script>
</head>
<body>
<form>
Search Text Here : <input type="text" id="Searchtxt" style="width: 226px" />
<br />
Select a Search Engine :
<input type="radio" name="SearchOption" id="Google" value="Google" />Google
<input type="radio" name="SearchOption" id="Yahoo" value="Yahoo" />Yahoo
<input type="radio" name="SearchOption" id="Both" value="Both" />Both
<br />
<button type="button" onclick="fnSearch()">Search</button>
</form>
</body>
</html>

Comments or Responses

Login to post response