0

I'm trying to reset a value when you click a button by simply setting the .val() with JQuery. The weirdest thing is happening- my code is ONLY working for the state dropdown but not the other inputs, which have their values set inline with SWIG interpolation like so:

<input type="text" class="moving-input form-control" id="first-name-search" value="{{search.firstName}}">

When this button is clicked:

<button type="reset" class="results-form-link" id="perform-new-search">Perform a New Search</button>

It should run this code:

$('#perform-new-search').click(function() {
    $('#first-name-search').val('hello');
    $('#last-name-search').val('');
    $('#results-states option:selected').val('Select State');
})

What's weird is if I try to run $('#first-name-search').val('hello'); in the console directly in the browser it works but it doesn't work when the button is clicked.

Linx
  • 753
  • 3
  • 15
  • 34

1 Answers1

0
$('#perform-new-search').click(function() {

    $('#first-name-search').val('hello');
    $('#last-name-search').val('');
    $('#results-states option:selected').val('Select State');
})

Seems like it's working,

check https://jsfiddle.net/aLLrku6r/

Neetigya
  • 121
  • 2
  • 10
  • Right it should work but something about the interpolation on the html input value itself is making it not work. (value="{{search.firstName}}") – Linx Apr 19 '17 at 18:41
  • this should be helpful - [link]http://stackoverflow.com/questions/1408289/how-can-i-do-string-interpolation-in-javascript – Neetigya Apr 19 '17 at 18:48