Reputation: 1
I have this code:
<script language="javascript">
var noun=["cat","mat","rat"];
var verb=["like","is","see","sees"];
var object=["me","a+noun","the+noun"];
var subject=["I","a+noun","the+noun"];
var sentence=(subject+verb+object);
function checkCorrectness(){
var input=document.getElementbyId("userInput");
if(input==sentence)
{
alert("congratulations your sentence is correct");
}
else if(input=="null"||"")
{
alert("your entered a blank text, please enter sentence");
}
else{
alert("Sorry, Your sentence is incorrect, your sentence should be in the form of a subject, verb and object. please try again");
}
};
</script>
</head>
<body>
<h1><font size="3" color="black" face="comic sans ms">Welcome to Micro English</font></h1>
<h2><font size="2" color="blue" face="comic sans ms">Please Enter a sentence in micro English in the box below</font></h2>
<form onsubmit="checkCorrectness();">
<input type="text" name="input" id="userInput"/>
<input type="submit"value="go"/>
</form>
but when I click the "go" button nothing happens.what could be the problem? I have tried changing the type of input but it has never ran, I had a similar program that did run but I just cnt put my finger on the problem here. please help
Upvotes: 0
Views: 454
Reputation: 493
this code is working ..
<script language="javascript">
var noun=["cat","mat","rat"];
var verb=["like","is","see","sees"];
var object=["me","a+noun","the+noun"];
var subject=["I","a+noun","the+noun"];
var sentence=(subject+verb+object);
function checkCorrectness(){
var input=document.getElementById("userInput").value;
if(input==sentence.length)
{
alert("congratulations your sentence is correct");
}
else if(input==null || input =="")
{
alert("your entered a blank text, please enter sentence");
}
else{
alert("Sorry, Your sentence is incorrect, your sentence should be in the form of a subject, verb and object. please try again");
}
};
</script>
</head>
<body>
<h1><font size="3" color="black" face="comic sans ms">Welcome to Micro English</font></h1>
<h2><font size="2" color="blue" face="comic sans ms">Please Enter a sentence in micro English in the box below</font></h2>
<form onsubmit="checkCorrectness();">
<input type="text" name="input" id="userInput"/>
<input type="submit"value`enter code here`="go"/>
</form>
Upvotes: 1
Reputation: 40393
getElementbyId
is missing the capital B
- should be getElementById
Also the things that I mentioned in the comments need to be fixed.
Upvotes: 0
Reputation: 11468
You should do this:
var input=document.getElementbyId("userInput");
var inputtext=input.value;
Now use inputtext instead of input for comparison.
Or just:
var input=document.getElementbyId("userInput").value;
Upvotes: 0