0

I'm creating a mock up version of google censorship for history class. I'm trying to modify the redirect url so I can put my own terms into the url:

function searchCensor() 
{
var keyTerms = document.getElementById("search").value;
if(keyTerms == "censorship")
    window.location = "http://andrewgu12.kodingen.com/history/censor.php";
else
    window.location = "https://www.google.com/#hl=en&output=search&sclient=psy-ab&q="+keyTerms+"&oq="+keyTerms+"&aq=f&aqi=g4&aql=&gs_l=hp.3..0l4.851563l851824l0l851964l3l3l0l0l0l0l171l359l1j2l3l0.&pbx=1&bav=on.2,or.r_gc.r_pw.r_cp.r_qf.,cf.osb&fp=bb242dc4ab43ba95&biw=1920&bih=963"
}

in the else block, I try to insert keyTerms into the URL, but I end up with undefined when the search begins. Any suggestions? Here is the URL for the website: http://andrewgu12.kodingen.com/history/

1
  • id's have to be unique. You have the same id (search) on your page twice. Commented Apr 18, 2012 at 3:33

2 Answers 2

1

The "Search" link on the top bar of the same page has the same id of search, thus when you do your document.getElementById('search'), javascript returns the first element in the DOM with id = search, which is the anchor on the top bar instead of your input.

You can instead give a name attribute to your search form:

<form id="searchBox" name="searchForm">
    <input type="text" id="search" name="search" size="85"><br>        
</form>

And in your js

var keyTerms = document.searchForm.search.value;
// rest of your code
Sign up to request clarification or add additional context in comments.

Comments

0

In the header bar at the top, you have a button labeled "Search" that also has the id "search". Try removing the id from that element.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.