简体   繁体   中英

Advance search function of google search using javascript but getting some problems

Below is the code of the form using which I'm trying to fetch the value for the query string.

 <form id="form1"> <label for="allthesewords"> all these words</label> <input type="text" id="allthesewords"> <br> <label for="thisexactwordphrase">this exact word phrase</label> <input type="text" id="thisexactwordphrase"> <br> <label for="anyofthese">any of these</label> <input type="text" id="anyofthese"> <br> <label for="noneofthese">none of these</label> <input type="text" id="noneofthese"> <br> <input type="submit" value="Advance Search" onClick="advanceSearch()"> </form>

This one is the javascript function where I'm building my query string.

 function advanceSearch(){ document.getElementById("form1").action="https://www.google.com/search?as_q="+document.getElementById("allthesewords").value+"&as_epq="+document.getElementById("thisexactwordphrase").value+"&as_oq="+document.getElementById("anyofthese").value+"&as_eq="+document.getElementById("noneofthese").value; return true; }

So, the actual problem is while clicking on the submit button it must redirect to this url https://www.google.com/search?as_q=Harvard%20univeristy%20students&as_epq=students%20of%20Harvard%20Univeristy&as_oq=Harvard&as_eq=almamater However, when I run my code it just redirects to this url: https://www.google.com/webhp .

Thanks in advance!!!!!

 <form action="https://www.google.com/search"> <p>Find page with</p> <input class="input_bar" type="text" name="as_q" placeholder="all these words"> <input class="input_bar" type="text" name="as_epq" placeholder="this exact word or phrase"> <input class="input_bar" type="text" name="as_oq" placeholder="any of these words"> <input class="input_bar" type="text" name="as_eq" placeholder="none of these words"> <input id="btn" type="submit" value="Advance Search"> </form>

Use it!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM