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);
}

6 Answers 6

3

Your email input doesn't have an ID:

<input type="text" name="email" id="email" />
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

0

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

Comments

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>

Comments

0

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

<input type="text" name="email" id="email" ></input>

Comments

0

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.