Solved

Hidden Field not updating in form

Posted on 2015-02-06
2
81 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

Space-Age Communications Transitions to DevOps

ViaSat, a global provider of satellite and wireless communications, securely connects businesses, governments, and organizations to the Internet. Learn how ViaSat’s Network Solutions Engineer, drove the transition from a traditional network support to a DevOps-centric model.

Question has a verified solution.

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

It is a general practice to get rid of old user profiles on a computer  in a LAN environment. As I have been working with a company in a LAN environment where users move from one place to some other place at times. This will make many user profil…
Active Directory replication delay is the cause to many problems.  Here is a super easy script to force Active Directory replication to all sites with by using an elevated PowerShell command prompt, and a tool to verify your changes.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

733 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