how do i pass control(text field) values from one html to other using hidden variables.

P

prabodhtiwari

function submitPartsForm(str) {

var count=document.getElementsByName("partId");
for(var i=0;i<count.length;i++)
{

document.mylist.myNum.value= document.getElementsByName("partNum")
(i).value;

}

document.forms["mylist"].submit();
}
myNum[] is a hidden variable and partNum is the name of a text field
that has many instances i mean there are many textfields with the same
name so it forms a column in a data table.
 
E

Erwin Moller

function submitPartsForm(str) {

var count=document.getElementsByName("partId");
for(var i=0;i<count.length;i++)
{

document.mylist.myNum.value= document.getElementsByName("partNum")
(i).value;

}

document.forms["mylist"].submit();
}
myNum[] is a hidden variable and partNum is the name of a text field
that has many instances i mean there are many textfields with the same
name so it forms a column in a data table.


Why not give each each textfield a unique name?
I cannot think of one good reason...

Regards,
Erwin Moller
 
D

Darko

function submitPartsForm(str) {
var count=document.getElementsByName("partId");
for(var i=0;i<count.length;i++)
{
document.mylist.myNum.value= document.getElementsByName("partNum")
(i).value;

document.forms["mylist"].submit();
}
myNum[] is a hidden variable and partNum is the name of a text field
that has many instances i mean there are many textfields with the same
name so it forms a column in a data table.


Why not give each each textfield a unique name?
I cannot think of one good reason...

Regards,
Erwin Moller


Try naming them as follows:
<input name="partnum[]" ...>
In PHP, these are automatically converted into an array inside your
protocol-dependent superglobal (_GET or _POST), so you can use them at
will, although, if this is a static html, why not really give them all
unique names, as Erwin suggested.
 
O

OmegaJunior

function submitPartsForm(str) {

var count=document.getElementsByName("partId");
for(var i=0;i<count.length;i++)
{

document.mylist.myNum.value= document.getElementsByName("partNum")
(i).value;

}

document.forms["mylist"].submit();
}
myNum[] is a hidden variable and partNum is the name of a text field
that has many instances i mean there are many textfields with the same
name so it forms a column in a data table.


One way would be to join the text values together using a join character
unlikely to appear in the texts, like so:

function submitPartsForm() {
var theNodeList = document.getElementsByName("partId");
var theNodeValues = document.forms["myList"].elements["theNodeValues"];
if(theNodeList&&theNodeValues) {
for (var i=0;i<theNodeList.length;i++) {
if (theNodeList.value) {
theNodeValues.value += ("|" + theNodeList.value.toString());
}
}
document.forms["myList"].submit();
}
}

(Above script assumes the form has a hidden input (not disabled), named
"theNodeValues".)

Then in your server-side script you can use whatever method your language
uses to split the string into parts using the "|" as a split character.
Usually this results in an array.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,484
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top