Help with drop down list

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

Help with drop down list

Post by littlecoder »

Hi Friends,

I want to get the value into '$txt' from an array of hidden fields named 'hd' . I tried the following code...it's not working
for($i=0;$<10;$i++)
{

<input type ="hidden" name="hd $i" value ="$i">

}
$txt = array();
for($i=0;$<10;$i++)
{
$txt[$i] = $_GET['hd'.$i];
echo $txt[$i]."<br>";
}

Any help will be greatly appreciated
User avatar
papa
Forum Regular
Posts: 958
Joined: Wed Aug 27, 2008 3:36 am
Location: Sweden/Sthlm

Re: Help with drop down list

Post by papa »

Mmm, first of all you need to give the hidden fields a proper name, secondly submit the data.

Say you have submitted the fields and returned an array:

Code: Select all

$hd = $_POST['hd'];
 
for($i=0;$i<count($hd);$i++)
{
 
$txt[] = $hd[$i];
 
}
A better way might be to:

Code: Select all

$hd = $_GET['hd'];
 
for($i=0;$i<count($hd);$i++)
{
 
echo $hd[$i]."<br />\n";
 
}
As you have already an array with the same values.
User avatar
requinix
Spammer :|
Posts: 6617
Joined: Wed Oct 15, 2008 2:35 am
Location: WA, USA

Re: Help with drop down list

Post by requinix »

Code: Select all

<input type ="hidden" name="hd[]" value ="$i">
To go with what dad said.
User avatar
aceconcepts
DevNet Resident
Posts: 1424
Joined: Mon Feb 06, 2006 11:26 am
Location: London

Re: Help with drop down list

Post by aceconcepts »

What do you want to do, loop the array values or simply copy the array itself to $txt?
littlecoder
Forum Commoner
Posts: 26
Joined: Fri Oct 17, 2008 4:36 am

Re: Help with drop down list

Post by littlecoder »

Hi ,

It was a problem with my AJAX . Managed to get through it .
Thank you for your suggestions
Post Reply