Solved

Hidden Field not updating in form

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

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Asp in script 6 38
Awk : two files math 8 20
jQuery Dialog Autoresize Bug 2 25
Making an "H1" a specific color only on a specific page. 3 27
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…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
This tutorial will teach you the core code needed to finalize the addition of a watermark to your image. The viewer will use a small PHP class to learn and create a watermark.
In a recent question (https://www.experts-exchange.com/questions/29004105/Run-AutoHotkey-script-directly-from-Notepad.html) here at Experts Exchange, a member asked how to run an AutoHotkey script (.AHK) directly from Notepad++ (aka NPP). This video…

860 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