Saturday, 15 February 2014

html - Passing a variable to Javascript -



html - Passing a variable to Javascript -

so i'm kind of javascript newbie , having problem figuring out how pass variable html template javascript.

i want pass search query user enters javascript.

here's template search query.

<form class="well-whatsnext form-search" style="text-align:center; border-radius:10px 10px 10px 10px; width:900px; height:0px;background-repeat:no-repeat;margin-bottom:100px;" action="/search/?q="> <center> <input type="text" id = "form-search" value="search stuff" class="input-xxlarge search-query" style="margin: 30px 0px 0px 70px; height:50px;width:600px;font-size:20px;vertical-align:middle;text-align:center;border-radius:10px 0px 0px 10px;float:left;border-right:0px;color:grey;border-right:0px;" name="q"> </center> <br> </form>

here's javascript snippet:

$("#form-search").click(function() { // sends event every time user clicks button mixpanel.track('mainsearch', {'query' : search-query, 'url' : window.location.pathname}); });

it clear search-query not right way refer query since i'm not getting right output want.

how capture variable of query searched user?

use plain javascript wherever possible.

{'query': document.getelementbyid('form-search').value}

javascript html

No comments:

Post a Comment