Im trying to call a function when user clicks on the navbar search button but it does not seem to call the javascript fuction and just loads the same page. I have looked at examples and other questions but I dont see anyhing wrong.. Any help would be much appreciated, Here is my code, It is in my Masterpage.aspx:
<div class='navbar-form navbar-left' role='search'>
<div class='inputgroup'>
<input class='form-control' id='navinput' type='text' placeholder='Search'/>
<button class='btn btn-default' type='submit' id='navsearchbtn' runat='server' onclick='NavToSearch();'>
<span class='glyphicon glyphicon-search'></span>
</button>
</div>
</div>
Here is my Js code (also in Masterpage.aspx): I just have the test redirect to see if it works. (The code that i want to implement is in comments please check that is okay as well, I then want to use the input text to search database)
<script type='text/javascript'>
function NavToSearch() {
window.location.href = 'Search.aspx';
/*var navsearchText = $('$navinput').text();
if (navsearchText == '')
{
$('$navinput').attr('placeholder', 'Enter Search Text');
return false;
}
else window.location.href = 'Search.aspx'; */
}
</script>
UPDATED script/function:
<script type='text/javascript'>
function NavToSearch()
{
var navsearchText = $('#navinput').text();
if (navsearchText == '')
{
$('#navinput').attr('placeholder', 'Enter Search Text');
return false;
}
else {
window.location.href = 'Search.aspx';
//return false;
}
/*OR
$(document).ready(function(){
var url = "OrderHistory.aspx";
$(location).attr('href',url);
})*/
}
</script>