Home javascript How to get a value from Input'a

How to get a value from Input’a

Author

Date

Category

Hello everyone. Tell me how to pick up the value from input ‘a. Such code does not work:

& lt; html & gt;
& lt; Head & gt;
& lt; script type = "text / javascript" & gt;
  var text = document.getelementsbytagname ("Input") [0];
  var val = text.innerhtml;
  Alert (Val)
& lt; / script & gt;
& lt; / Head & gt;
& lt; Body & gt;
& lt; form action = "#" & gt; & lt; Input Type = "text" value = "Some Text Here ..." / & gt;
& lt; Input Type = "submit" / & gt;
& lt; / form & gt;
& lt; / body & gt;
& lt; / html & gt;

Firebug says: Text Is undefined


Answer 1, Authority 100%

var text = document.getelementsbytagname ("INPUT") [0];
var val = text.value;
Alert (VAL);

Answer 2, Authority 62%

Try

& lt; script type = "text / javascript" & gt;
   var text = document.getelementsbytagname ("Input") [0];
   var val = text.value;
   Alert (Val)
 & lt; / script & gt;

move after form. Or wrap in online.


Answer 3, Authority 25%

& lt; script type = "text / javascript" & gt;
 FUNCTION GETVALUE () {
  Var Text = Document.getelementByid ("Input_form"). Value;
  Alert (Text);
 }
& lt; / script & gt;
................................
& lt; Input Type = "Text" id = "input_form" value = "Some Text Here ..." / & gt;
& lt; Input Type = "submit" onClick = "GetValue ()" / & gt;

Programmers, Start Your Engines!

Why spend time searching for the correct question and then entering your answer when you can find it in a second? That's what CompuTicket is all about! Here you'll find thousands of questions and answers from hundreds of computer languages.

Recent questions