Getting HTML text input value

Let's say I have such an HTML form to collect an email from a website visitor:

<form name="input" action="handle_email.php" method="post"> Email: <input type="text" name="email" /> <input type="submit" value="Newsletter" /> </form> 

Now that the submit button is pressed, I can get the value of the email field in handle_email.php using $ _POST ["email"]. But I will say that I would like to use the value of inputting email text elsewhere. Is it possible to get the email value “outside” the form processing?

UPDATE: Thanks to everyone for their quick answers. What I'm trying to do is get a mailbox to perform a double duty. For example, I renamed the submit button to "Newsletter" in the code above. When this button is clicked, the handle_email.php script will simply register the user for newsletters. However, I also have a “Registration” link on the same page, which redirects the visitor to the registration form, where they can enter a lot of other information if they want. Now, if a user accidentally entered data in an email text field, I would like to send it to the registration page so that the field is pre-filled. For example:

 <a href="http://mywebsite.com/register?user_email="[how can I put the email here?]"/>Register</a> 

I apologize for not being clear enough in my original post.

+8
html input forms
source share
6 answers

See my jsFiddle here: http://jsfiddle.net/fuDBL/

Whenever you change the email field, the link is updated automatically. This requires a small amount of jQuery. So, now your form will work as needed, but your link will be dynamically updated, so when someone clicks on it, it contains what they entered in the email field. You must confirm the entry on the reception page.

 $('input[name="email"]').change(function(){ $('#regLink').attr('href')+$('input[name="email"]').val(); }); 
+9
source share

If you want to use the email input value somewhere else on one page, for example, to perform some validation, you can use JavaScript. First, I would assign the id attribute to the email text box:

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

and then I would get the value using JavaScript:

 var email = document.getElementById('email').value; 

From there, you can perform additional processing of the "email" value.

+18
source share

Depending on where you want to use email. If it's on the client side without sending it to a PHP script, jQuery (or javascript) can do the trick.

I created a fiddle to explain the same thing - http://jsfiddle.net/qHcpR/

It has a warning that turns off when loading and when you click on the text box.

+1
source share

If your page is refreshed when submitted - yes, but only through querystring: http://www.bloggingdeveloper.com/post/JavaScript-QueryString-ParseGet-QueryString-with-Client-Side-JavaScript.aspx (you should use the method "GET" then). Alternatively, you can return its value from php script.

+1
source share

Yes, you can use jQuery to do this, idea

Use the hidden value in your form and copy the value from the external text field to this hidden value immediately before submitting the form.

 <form name="input" action="handle_email.php" method="post"> <input type="hidden" name="email" id="email" /> <input type="submit" value="Submit" /> </form> <script> $("form").submit(function() { var emailFromOtherTextBox = $("#email_textbox").val(); $("#email").val(emailFromOtherTextBox ); return true; }); </script> 

also see http://api.jquery.com/submit/

+1
source share

just use simple javascript:

 <form name="input" action="handle_email.php" method="post"> Email: <input type="text" name="email" /> <input type="submit" value="Newsletter" /> </form> <a href="javascript:var the_mail = document.getElementByName('email').value; window.location = 'http://mywebsite.com/register?user_email=' + the_email;">Register</a> 

You can also change the type of email input, for example:

0
source share

All Articles