0

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

10
  • You're comparing the element itself, not its value - should be var input=document.getElementbyId("userInput").value; Commented Aug 15, 2013 at 19:12
  • 2
    What does valueenter code here supposed to mean? Commented Aug 15, 2013 at 19:12
  • 1
    What is this valueenter code here`` ? Commented Aug 15, 2013 at 19:12
  • Also, else if(input=="null"||"") - you're checking for string comparison against the string "null", which I'm assuming is not what you want. Plus the ||"" won't work - the language doesn't work that way. You probably want if (!input), which will look for any "falsy" value. Commented Aug 15, 2013 at 19:13
  • Joe I did try that but the same thing happens, the page loads but when I enter text into the textbox and click on the button nothing happens Commented Aug 15, 2013 at 19:15

3 Answers 3

1

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>
Sign up to request clarification or add additional context in comments.

1 Comment

this code is working but i am not satisfied with the line var sentence=(subject+verb+object);// what you want to do here
0

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;

Comments

0

getElementbyId is missing the capital B - should be getElementById

Also the things that I mentioned in the comments need to be fixed.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.