Ok so this should be a fairly easy thing to do however I think I am missing something. I have an input field like so.
<input id="jobSearchField" class="searchField" runat="server"
onkeypress="javascript:GoToFunc(event, this.value)" type="text"
onfocus="if (this.value == 'Seach jobs by JobID, JobTitle, Keywords, or Location') this.value=''"
value="Seach jobs by JobID, JobTitle, Keywords, or Location" />
I also have a button to the right like so.
<button id="filterSubmit" runat="server" class="filterSubmit">Submit</button>
Here is my javascript that I “attempted” to build.
<script type="text/javascript">
function GoToFunc(e, value) {
if (e.keyCode == 13) {
var location = document.location.href + "&query=" + value;
document.location.href = location;
document.open();
}
}
</script>
My javascript function that I “attempted” to build was suppose to pass that query string back into the url so that I could parse what the user wanted. I am using ASP.NET and C# for the language.
So the question is how do I return back in the url as a parameter what the user typed?
First off you are recreating what a form does. If you had just a form it would work.
For your code, stop the enter keys action by returning false. You need to add return to the event handler too. This also expects that the querystring value is not there already.