javascript - jQuery Code won't connect to search form -
this question pertains this question/post. have search form requires: a: pull user input search form our backend can provide user relevant search results. b: need able insert default input either, or both, search fields enhance user search experience. should replace placeholder values.
i have tried following code in main.js file (linked testpage.html):
$(document).ready(function(){ $("#btn-search").click(function(e){ e.preventdefault(); var x = $("#keyword").val("nurse"); var y = $("#location").val(); $("#keyword").attr("value", x); $("#location").attr("value", y); }); });
i have tried following:
$(document).ready(function(){ $("#btn-search").click(function(e){ e.preventdefault(); $("#keyword").val(nurse); $("#location").val(); }); });
do know why wouldn't work? tried put in body of page:
<script> $("#btn-search").click(function(e){ e.preventdefault(); $("#keyword").val(nurse); $("#location").val(); }); </script>
here's html form:
<form class="form-inline no-margin center-block" action="http://www.somewebsite.com/unknown" method="post" role="form"> <div class="row"> <center> <fieldset> <!-- search input--> <div class="form-group center-block"> <div class="col-sm-4"> <label class="sr-only" for="keyword">from:</label> <input id="keyword" name="keyword" type="search" placeholder="keyword" value="" class="form-control input-lg"> </div> </div> <!-- search input--> <div class="form-group center-block"> <div class="col-sm-4"> <label class="sr-only" for="location">from:</label> <input id="location" name="location" type="search" placeholder="city, state, or zip code" class="form-control input-lg"> </div> </div> <input type="hidden" name="unknown" value="unknown"> <!-- button --> <div class="form-group center-block"> <div class="col-sm-2"> <button type="submit" id="btn-search" name="btn-search" class="btn btn-primary btn-lg btn-tusaj">search</button> </div> </div> </fieldset> </div> </form>
$(document).ready(function(){ $("#btn-search").click(function(e){ e.preventdefault(); $("#keyword").val("nurse"); $("#location").val(""); }); });
val()
requires string
. using string should solve problem.
reference: http://api.jquery.com/val/
Comments
Post a Comment