javascript function doesnt work -
I will repeat my question
I have written this code and I do not understand that Why does it work?
I wrote the sandwich option I wrote in the website that an order is made to make something that one person comes to the website and then It is sandwich displayed and content in sandwich (contents are all arrays)
I also have my HTM Will add L code, and if anyone can write an example of the correct code will be very much useful for me.
Javascript code:
var avucado = ["eggs", "avucado", "tommato", "mayonnaise", "pickle", "gumba"]; Var Eggassald = ["Egg", "Dill", "Mayonnaise", "Pickle"]; Var tuna = ["tuna", "coriander", "pickle", "mayonnaise", "gamba"]; Var cheeze = ["Yellow Chase", "Mayonnaise", "Toetato", "Cucumber"]; Ware sausage = ["sausage", "mustard", "mayonnaise", "totoato", "pickle"]; Var choice1 = ("You chose:"); Var choice2 = ("The contents of your sandwich are:") var food = function (foodName) {if (document.getElementById ("input"). Value = avucado) {document.write (like 1 + "" + 'avucado. '+ "
< / Pre>
" + + "+ Option 2 +" "+ avucado +".);); } And if (document.getElementById ("Input") value = eggSalad) {document.write (prefer1 + "" + egg salad "+"
" + "" + 2 + + + + + Egg Sallad + ".); } And if (document.getElementById ("Input"). Value = tuna) {document.write (like 1 + "" 'tuna.' + "
+ "" + Likes 2 + "" + tuna + "."); } And if (document.getElementById ("Input"). Value = cheeze {document.write (like 1 + "+ 'yellow chase.' +"
< "+" "+ Likes2 +" + + + fibers + ".); } And if (document.getElementById ("input") value = sausage) {document.write (like 1 + "" 'tuna. + "
"" + 2 likes + + "+ tuna +". "); } Else (document.getElementById ("input" .value! = Avucado, eggSalad, tuna, chase, sausage) {document.write ("error, please select a sandwich in the list)";}};HTML code:
Hello World! Title> ; & Lt; Meta http-equiv = "Type content" content = "text / html; charset = UTF-8" /> gt; lit script type = "text / javascript" src = "script.js" & gt; Script>
Body dir = "rtl">is the sandwich you want to order? & Lt; / h1 & Gt; & lt; form & gt; & lt; Input Type = "text" id = "input" /> gt; & lt; br / & gt; button type = "button" id = "button" value = "submit" onclick = "food ()" & Gt; Submit & lt; / button & gt; & lt; br / & gt; & lt; / form> & lt; / body & gt; & lt p>
Replace all occurrences:
document.getElementById ("input"). With value =
:
document.getElementById ("Input"). Value == cod e> pre>
statement to fix something:single "equal to" sign (
=
) is a double - "equal to" sign (==
) IsIn your
if
, you were specifying the contents of the food in the.value
of input instead of checking equality.To check that the
value
is in the array, you should do something like this:if (avucado.indexOf (document.getElementById ( "Input") .Value! == -1) {
So, if the value is in the array
avucado
, then what isis below
.Finally, this requires your <<> << code> other
else (document.getElementById ("input" .value! = Avucado, eggSalad, tuna, cheeze, sausage) {document.write ("Error, one of the sandwiches in the list is selected");}
Replace with:
else if (avacado.concat (egg salad, tuna, chase, sausage) .indexOf (document.getElementById ("input") .value) == -1) {document.write ( "Error, please select a sandwich in the list");}
Now, instead of
document.write ("text")
, I dump manipers Using I suggest:In your HTML, add an element like this:
& lt; span id = "message" & gt; & lt; / span
Then, in your JS:.
document.getElementById ("message") innerHTML = "text";
Comments
Post a Comment