Dropdwon list in html

HTML, CSS and anything else that deals with client side capabilities.

Moderator: General Moderators

Post Reply
pooja1110
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2014 12:17 am

Dropdwon list in html

Post by pooja1110 »

I need some help. I am a newbie to php ..
What I am trying to do is to parse an xml file and create a drop-down for the user.
I have attached how my drop down list looks currently.
What I want to do is to add a sub list to each option.. say to networkSecurity I want to add option a,b,c,d which I have to read from the same xml file.
How this can be done ?
To create normal drop-down list my code looks like

Code: Select all

<?php

    $xml=simplexml_load_file('info.xml');
    foreach($xml->testcase as $var){

        $var=explode('/',$var->script);

        $module[] =$var[2];
	
        $testName[] = end($var);
 }
        echo "<pre>";
        print_r($module);
		
       
        print_r($testName);
		
		$modules = array_unique($module); 
		
foreach($modules as $newarr) 
{

 $newmodules[]=$newarr;
 }

 print_r($newmodules);
 	
 ?> 
<select name="module" id="Module">
        <?php
        $i=0;
        foreach($newmodules as $mod)
        {
            ?>
            <option value="<?php echo $mod;?>"><?php echo $newmodules[$i];?></option>
            <?php
		 $i++;
	   }
    ?>
    </select>
Attachments
drop-down list
drop-down list
pbs
Forum Contributor
Posts: 230
Joined: Fri Nov 07, 2008 5:31 am
Location: Nashik, India
Contact:

Re: Dropdwon list in html

Post by pbs »

may this will help you

Code: Select all

<select name="module" id="Module">
<?php
	if (is_array($newmodules) && count($newmodules) > 0)
	{
		foreach($newmodules as $newmodules_key => $newmodules_value)
		{
?>
			<option value="<?php echo $newmodules_key;?>"><?php echo $newmodules_value;?></option>
<?php
   		}
	}
?>
</select>
pooja1110
Forum Newbie
Posts: 4
Joined: Thu Mar 13, 2014 12:17 am

Re: Dropdwon list in html

Post by pooja1110 »

hey it is doing the same work .. !!
ryancody
Forum Newbie
Posts: 14
Joined: Wed May 21, 2014 1:48 am

Re: Dropdwon list in html

Post by ryancody »

Simple way to create a drop down list in html
<select>
<option>Milk</option>
<option>Coffee</option>
<option>Tea</option>
</select>
Post Reply