KillerDoge KillerDoge - 8 months ago 42
HTML Question

Using IF OR Else in Java Script

I am currently making a website for my Gaming Community, I made it so it looks like a Linux Terminal (Site is if you're curious) And I'm a beginner "programmer", I need a little help, when I type in one of the words, it won't do anything, this is my whole index.html code:

I couldn't post all my code here sorry!

This is the part where I got stuck:

var code = (e.keyCode ? e.keyCode : e.which);
var input = document.getElementById("text");
if (code == 13) {
if (input == "Hungarian" || "Magyar") { / hungarian / hungarian.html)

<mark class="smallwhite">Type in the desired language:</mark>
<input type="text" id="input" size="26">


You have two errors in your code :

1) You need to get the actual value entered inside the input :

// This only retrieve the HTML element <input> 
var input = document.getElementById("text");
// To get the value you need to : 
var value = input.value;

// Will print the entered value in firebug /developer console of your browser

2) Your test condition is incorrect :

// This will always evaluate to true (testing the string "Magyar" is always true)
// And you need to test for the value, not the "input" (HTML Element)
if (input == "Hungarian" || "Magyar") { 

should be

if (value == "Hungarian" || value == "Magyar") {