Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 57
  • Last Modified:

Javascript: assign value to hidden form element

Thank you for looking at my question,

I have a user input form (php) that has some javascript validation which should, if the conditions are met, assign a value to a hidden form element but it isn't working and I can't see why.
	<form name="Form1" action="Forms/Section1.php" method="GET" onSubmit="return jsValidate()">
		<input type="hidden" name="StockItem" />

Open in new window


The javascript validation looks like this
if (z.length == 23){
	if (z.slice(0,2) == "VE" || z.slice(0,2) == "SE"){
		
		//alert("So Far So Good");
		
		document.getElementById("StockItem").value = 1; //Full Build
		alert (document.getElementById("StockItem").value);
	} else {
		errorcount++;
		document.getElementById('VECO').style.color='#FF0000';
	}
} else if (checknum==1){
	
	//alert("So Far So Good");
	
	document.getElementById("StockItem").value = 0; //Component
	alert ("Assembly Stock Item: " + document.getElementById("StockItem").value);
} else {
	errorcount++;
	document.getElementById('VECO').style.color='#FF0000';
}

Open in new window


If either of the conditions are met (z == 23 characters starting VE or SE, or checknum == 1)  then, when it's not commented out, the "So Far So Good" alert appears on the screen but the following
alert(document.getElementById("StockItem").value);

Open in new window

doesn't
and no value is assigned to the StockItem element - as can be seen in the address of the php page the data should pass to
http://xx.xx.xx.xx/ed1/Forms/Section1.php?StockItem=&Meter=1000&ProdnOrder=553456789&SalesOrder=9999&SerialNo=&VECode=VE884S05E0G0T01D0004000

Open in new window


What am I missing?
0
Crxfrd
Asked:
Crxfrd
1 Solution
 
Marco GasiFreelancerCommented:
The element you want assign a value to has no id, onky the name. Just change it to this
	<form name="Form1" action="Forms/Section1.php" method="GET" onSubmit="return jsValidate()">
		<input type="hidden" name="StockItem" id="StockItem" />

Open in new window

0
 
CrxfrdAuthor Commented:
Bingo! Thank you
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!

Tackle projects and never again get stuck behind a technical roadblock.
Join Now