PHP Developers Network

A community of PHP developers offering assistance, advice, discussion, and friendship.
 
Loading
It is currently Tue Sep 29, 2020 3:52 pm

All times are UTC - 5 hours




Post new topic Reply to topic  [ 4 posts ] 
Author Message
 Post subject: Dropdwon list in html
PostPosted: Thu Mar 13, 2014 12:31 am 
Offline
Forum Newbie

Joined: Thu Mar 13, 2014 12:17 am
Posts: 4
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

Syntax: [ Download ] [ Hide ]
<?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:
File comment: drop-down list
modules.jpg
modules.jpg [ 13.99 KiB | Viewed 3956 times ]
Top
 Profile  
 
PostPosted: Thu Mar 13, 2014 12:48 am 
Offline
Forum Contributor

Joined: Fri Nov 07, 2008 6:31 am
Posts: 230
Location: Nashik, India
may this will help you

Syntax: [ Download ] [ Hide ]
<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>
 

_________________
|


Top
 Profile  
 
PostPosted: Thu Mar 13, 2014 12:57 am 
Offline
Forum Newbie

Joined: Thu Mar 13, 2014 12:17 am
Posts: 4
hey it is doing the same work .. !!


Top
 Profile  
 
PostPosted: Fri May 23, 2014 1:15 am 
Offline
Forum Newbie

Joined: Wed May 21, 2014 1:48 am
Posts: 14
Simple way to create a drop down list in html
<select>
<option>Milk</option>
<option>Coffee</option>
<option>Tea</option>
</select>


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 

All times are UTC - 5 hours


Who is online

Users browsing this forum: No registered users and 9 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Jump to:  
Powered by phpBB® Forum Software © phpBB Group