user2152375
user2152375

Reputation: 11

Fixing my javascript search bar

So I was programming my search bar and I can't quite know why it's not working. I am wanting when a user types "forums" it says a message and when they click okay it sends them to the forums, but I was testing to see if it would display the alert it and I couldnt get it to say anything.

HTML

<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>website name / slogan</title>

    <link rel="stylesheet" type="text/css" href="css/bootstrap.css" />
    <link rel="stylesheet" type="text/css" href="css/bootstrap.min.css" />
    <link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.css" />
    <link rel="stylesheet" type="text/css" href="css/bootstrap-responsive.min.css" />

</head>

<body>
<div class="row">
    <div class="span12">
        <form method="get" action="/" class="form-inline" >
            <input name="q" class="span5" id="searchBar" type="text" placeholder="Click below on how to use" />
            <button type="submit" id="submit" class="btn btn-primary"> <i class="icon-search icon-white"></i></button>
        </form>
    </div>
</div>

<script type="text/javascript" src="js/bootstrap.js"></script>
</body>

Javascript

function myNavSystem() {
    var mySearchBar = document.getElementById('searchBar');
    if(mySearchBar = "forums")
        document.getElementById('submit');
        alert("you have tried accessing forums")
    else
        alert("You have entered invalid text, try again.")
}

Upvotes: 0

Views: 260

Answers (1)

Tchoupi
Tchoupi

Reputation: 14681

One obvious mistake is that you forgot curly braces in your if / else statement (and semicolons).

if(mySearchBar.value == "forums") {
    document.getElementById('submit');
    alert("you have tried accessing forums");
} else {
    alert("You have entered invalid text, try again.");
}

Upvotes: 2

Related Questions