Reputation: 1
I am trying to change the value of the form's action
attribute based on the value a user enters into the wetterInput
field in the code below.
<form method="POST" class="formSearch" id="formSearch" action="">
<input type="text" name="wetterInput" id="wetterInput" class="wetterInput" />
<input type="submit" class="weatherButton" value="Suchen" />
</form>
For example, if the user inputs the text "town", the form's action should be updated to action="/folder/town/"
.
I've tried the following, but have been unable to get it to work:
$(document).ready(function() {
$('#wetterInput').on('focusout', function() {
var action = document.getElementById("wetterInput").value;
$("#formSearch").attr("action", "/folder/" + action + "/");
});
});
Upvotes: 0
Views: 186
Reputation: 7327
document
as documetn
.focusout
doesn't work in Firefox – you should probably be using blur
instead.var action = this.value;
would probably be cleaner than var action = documetn.getElementById("wetterInput").value;
Working JSFiddle: http://jsfiddle.net/e789ueb3/1/
Upvotes: 2