2

I am trying to get value of input using js but it doesn't work. Where is my mistake?

Alert doesn't work.

<body>
   <form name="inputform" id="form1" action="html_form_action.asp" method="get" style="visibility:hidden">
      Email: <input type="text" name="email" ></input>
      <input type="button" value="Gönder" onclick="CreateU()"></input>
   </form>
</body>

js file:

var xmail="";
CreateU = function(){
  var xx = "";
  xmail=document.getElementById('email').value;
  alert(xmail);
  xx= myAddress + xmail + ans + tf;
  window.location.assign(xx);
}
Asif Raza
  • 3,435
  • 2
  • 27
  • 43
user1942359
  • 1,449
  • 3
  • 13
  • 8

6 Answers6

3

Your email input doesn't have an ID:

<input type="text" name="email" id="email" />
CodingIntrigue
  • 75,930
  • 30
  • 170
  • 176
1

Add id to your "Email" input: <input type="text" name="email" id="email" ></input>

Have a look: http://jsfiddle.net/K8kp9/

Note that now you possibly see nothing because of style="visibility:hidden" at your form tag..

Have some reading: Difference between id and name attributes in HTML

Community
  • 1
  • 1
Ivan Chernykh
  • 41,617
  • 13
  • 134
  • 146
0

email is a name, just change 'name' to 'id' ^^

0

please set the id in email

 <body>
    <form name="inputform" id="form1"  action="html_form_action.asp" method="get"       style="visibility:hidden">
    Email: <input type="text" name="email" id="email" ></input>
    <input type="button" value="Gönder" onclick="CreateU()"></input>
akash
  • 2,117
  • 4
  • 21
  • 32
0

use id attribute in the input to get the value by using document.getElementById().

<input type="text" name="email" id="email" ></input>
jothikannan
  • 67
  • 2
  • 7
0

you forgot to mention id='email' in your input element.

schnill
  • 905
  • 1
  • 5
  • 12