Solved

Hidden Field not updating in form

Posted on 2015-02-06
2
82 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
In threads here at EE, each comment has a unique Identifier (ID). It is easy to get the full path for an ID via the right-click context menu. However, we often want to post a short link within a thread rather than the full link. This article shows a…
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 the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

705 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