KillerDoge KillerDoge - 4 months ago 11
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 http://fluffykillers.ml/ 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:

http://pastebin.com/CuN5cq92

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") {
window.open(Lang / hungarian / hungarian.html)
}
}

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

Answer

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
console.log(value); 

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") {