user2121982
user2121982

Reputation: 17

Function for Input and Text

I am trying to create a function that puts the text you click on into 3 input boxes in order from box 1 to Box 3. However with the function below, the text appears in Box 1 & 3 at the same time and then Box 2. How can I fix this?

function setInput(id){
if(hasbeenset)
{
    document.getElementById("myinput2").value= id;
}
else if
(hasbeenset=true)

{
    document.getElementById("myinput").value=id;

}
   else 
    (hasbeenset=true)
   {
    document.getElementById("myinput3").value=id;

   }


   }

Upvotes: 1

Views: 50

Answers (1)

robbrit
robbrit

Reputation: 17960

The syntax is wrong because you haven't specified a condition for your else if:

}
else if {  // invalid syntax

You should have:

}
else if ( condition goes here ) {

UPDATE:

With your edits, you now have two problems.

else if
(hasbeenset=true)

This will set hasbeenset to true, and will always succeed because the expression evaluates to true.

else 
(hasbeenset=true)

This is invalid syntax, an else block never takes an expression.

Upvotes: 5

Related Questions