Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PHP equiv for Javascript LOOP to assign sequential form field values

Status
Not open for further replies.

LOOP123

Programmer
Mar 7, 2008
10
CA
Hello,

I'm trying to convert some javascript to a PHP equivalent (I'm a little new to PHP).

Basically, I'm using a javascript loop to automatically assign form values to similar fields. Here is my javascript code:
Code:
var N   = new Array();

for (var x = 0; x < 5; x++){
    N[x] = document.forms["frmOpt1"].elements["opt1N"  + x].value;
}
My question is, how do I convert the above to a PHP equivalent?

Thanks so much in advance!
 
assuming a get request
Code:
for ($x = 0; $x < 5; $x++){
    if (isset($_GET['opt1N".$x])){
      $N[] = $_GET["opt1N" . $x];
    } else {
      $N[] = 'off';
    }
}

for a posted form, obviously substitute $_POST for $_GET
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top