javascript - TextBox and Button JS Onclick -
i have textbox. wanted use js onclick append input in textbox "btngo" button below it's not working:
document.getelementbyid('btngo').onclick = function() { var search = document.getelementbyid('dlrnum').value; window.location.url = "http://consumerlending/app/indirect/dealercomments.aspx?dlrnum=" + search; }
<input id="dlrnum" type="text" name="dlrnum" autocompletetype="disabled" class="ui-autocomplete-input" autocomplete="off"> <input id="btngo" type="submit" value="go" name="go" runat="server">
what missing?
you had several problems there: 1. <input>
elements part of form
, when click on submit button - form submit, unless prevent it. 2. need use window.location.href
(and not .url
).
here fix code:
document.getelementbyid('btngo').onclick = function(e) { e.preventdefault() var search = document.getelementbyid('dlrnum').value; window.location.href = "http://consumerlending/app/indirect/dealercomments.aspx?dlrnum=" + search; }
note
e
element insidefunction(e)
- it's there can use event object prevent default behavior of form submission.
Comments
Post a Comment