iJonathan
iJonathan

Reputation: 21

If-else for value javascript

now, I'm making a chatbox. This is the code of the page were you can type in your name, but I will, when a user type my name (name of the webmaster) that the user got an error, because there aren't the webmaster. My if-else function won't work. Is there anyone who can help me? Thanks

<html>
    <head>
<title></title>
<style type="text/css">

    #main{
            width: 400px;
            height: 300px;
            background-color: #333;
            text-align: center;
            position: absolute;
            color: white;
            left:50%;
            margin-left: -200px;
            top: 50%;
            margin-top: -150px;
            }

        </style>
        <script type="text/javascript" src="http://code.jquery.com/jquery-1.7.2.min.js"></script>
        <script type="text/javascript">

        function show() {
        var text = document.getElementById('text');
        if (text.value == "Jonathan Cazaerck"){alert("Deze gebruiker mag u niet gebruiken");}
        else{
        $.post("processing.php", { stage: "newuser", username: $("#text").val()}, function(data){
        window.location = ("newsession.php?user="+data);}
        );}
  </script>
    </head>
    <body>
    <div id="main"><br><br><br><br>
    Geef je voor- en achternaam op: <br><br><input type="text" size="35" id="text"/><button id="send" onclick="show();">Verzenden</button>
    </div>
    </body>
</html>

Upvotes: 0

Views: 3957

Answers (2)

aquinas
aquinas

Reputation: 23786

You're missing a closing } in your show function.

Upvotes: 1

Dan O
Dan O

Reputation: 6090

You need one more } at the end of your code.

    <script type="text/javascript">

    function show() {
    var text = document.getElementById('text');
    if (text.value == "Jonathan Cazaerck"){alert("Deze gebruiker mag u niet gebruiken");}
    else{
    $.post("processing.php", { stage: "newuser", username: $("#text").val()}, function(data){
    window.location = ("newsession.php?user="+data);}
    );}
    }

Upvotes: 1

Related Questions