Q:

defining onclick navigation using jQuery

I'm trying to do onClick function, that will redirect the user after inputing specific text to searched page... When in function definition I use only simple if... else than everything is all right. Problem appears when I try to use multiple else if.
<input id="naszInput"></input>
<button onclick="searchMe();">Search</button>

and function definition:
<script>
function searchMe () {

if ($("#naszInput").val().toLowerCase() == "zara")
{
    window.location.href = 'zara.html';
}

    else if ($("#naszInput").val().toLowerCase() == "orsay")
{
    window.location.href = 'orsay.html';
}

else
{
    $("#naszLabel").text("cannot find!");
}
}
</script>

Any ideas why is it that?
And this is what Chrome console tells me about this error:
Uncaught ReferenceError: searchMe is not defined app.html:1
onclick

A:

I would remove the onclick attribute on the button, and add an id attribute which can be used to hook up a click event. Also, I would suggest moving your javascript into an external file.
<button id="btnSearch">Search</button>

<script>
function searchMe () {

if ($("#naszInput").val().toLowerCase() == "zara")
{
    window.location.href = 'zara.html';
}

    else if ($("#naszInput").val().toLowerCase() == "orsay")
{
    window.location.href = 'orsay.html';
}

else
{
    $("#naszLabel").text("cannot find!");
}
}
    $(function(){
      $('#btnSearch').click(searchMe);

    })
</script>

