Solved

Hidden Field not updating in form

Posted on 2015-02-06
2
77 Views
Last Modified: 2015-02-06
I was doing some testing and I can't figure out why my hidden field is not being populated? The value stays blank.
<!DOCTYPE html>
<html lang="en">
  <head>
	<script>
	function populateUser(){
		var currUser = "test@yopmail.com";
	    document.getElementById("txtUserName").value = currUser;
	    return true
	};
	</script>

  </head>
  <body>
  	<form action="www.somedomain.com" name="loginform" method="post" target="bottom">
	  <input type="hidden" id="txtUserName" name="txtUserName" value="" />
	  <input type="submit" name="submit" onsubmit="return populateUser()" value="start logon"/>
	</form>
  </body>
</html>

Open in new window

0
Comment
Question by:894359
2 Comments
 
LVL 44

Accepted Solution

by:
Rainer Jeschor earned 500 total points
ID: 40593111
Hi,
please move the onsubmit to the form element and not in the submit button:
<form action="www.somedomain.com" onsubmit="return populateUser()" name="loginform" method="post" target="bottom">
	  <input type="hidden" id="txtUserName" name="txtUserName" value="" />
	  <input type="submit" name="submit"  value="start logon"/>
	</form>

Open in new window

http://jsfiddle.net/EE_RainerJ/6a0pv2gk/

This should do the trick.
HTH
Rainer
0
 

Author Comment

by:894359
ID: 40594055
Not good working when you are tired! my bad! :0)
0

Featured Post

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

This article will show, step by step, how to integrate R code into a R Sweave document
Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …

706 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now