Welcome to Dream.In.Code
Become an Expert!

Join 150,011 Programmers for FREE! Get instant access to thousands of experts, tutorials, code snippets, and more! There are 1,448 people online right now. Registration is fast and FREE... Join Now!




Drop Down Menu Problem

 
Reply to this topicStart new topic

Drop Down Menu Problem, Can't refresh values when i select an item from a drop down menu

Lord Hadies
7 Dec, 2006 - 02:30 AM
Post #1

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
ok...
firstly html is full of S**t...
now the question...

ok i'm writing a page that has a drop down menu. There are (for eg 3) interfaces.
this is taken from an array. the array works fine.
[0] [0] = the first interface with the number of listings in this interface
[0] [1] = the name of the interface
[0] [2..x]= the details of the interface...
[1][0] = second interface with the number of listings in this interface..etc

thats how the array is setup...

ok...
now i display the name of the interface in a drop down menu...
this is done with a for loop (the whole code will be given below)...
ok once the for loop is over the particular details of the interface are given below it.
the thing is i'm struggling with the following...
when the user will select a different interface (from the drop down menu) i want the page
to be refreshed with the chosen interfaces values. the reason i'm struggling is that the form has to post the interface values to the submit page. hence i can't post to the page itself.
i am really stuck hence i can only go this far. (i tried onclick but then that didn't work and i found out it is a java command. i'm not allowed to use jave at all in this program.

here is the code
CODE

<?php //--- This function shows the details depending on the interface selected
      function give_details($interfaces,$i,&$detail1,&$detail2)
      {
        $detail1=$interfaces[$i][2];
        $detail2=$interfaces[$i][3];
      } //--- end function give_details()
?>
        

<?php //--- This function displays the form
      function show_form($CHECKED1,$CHECKED2,$CHECKED3)
       {
         get_info($num_of_interfaces,$interfaces); ?>
             
          <form action="submit_config.php" method="POST">
            <!-- interfaces option -->    
        <b>Interfaces: </b>
               <select size="1" name="Interface">
<?php
                  for ($i=0;$i<$num_of_interfaces;$i++)
                  {  ?>
                           <option value=<?php echo $interfaces[$i][1]; ?> >
                               <?php echo $interfaces[$i][1];?>
                          </option>
<?php            }  //--end for
                    ?>
                  </select>            
                            
             <br>
                <b>detail1: </b>
<?php       echo $detail1; ?>
            <br>
            <b>detail2   : </b>
<?php       echo $detail2; ?>
            <br>            
             <br>
             <!-- And now for the buttons -->    
             <div align="right">
                <input type="SUBMIT" name="accept" value="SUBMIT"> <b>   </b>
                <input type="RESET"  value="DEFAULT VALUES">   <b>   </b>
             </div>
             <br>
             <br>
             <br>
           </form>
<?php } ?> <!-- End of Function show_form() -->
    


Please help ASAP!!!!! (don't worry its not homework...its for work smile.gif )
User is offlineProfile CardPM
+Quote Post

snoj
RE: Drop Down Menu Problem
7 Dec, 2006 - 04:06 PM
Post #2

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
What is this interface stuff? Remember, PHP outputs data (in this case HTML) and so "submit_config.php" needs to output whatever interface the user has selected.
User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Drop Down Menu Problem
11 Dec, 2006 - 12:51 AM
Post #3

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
QUOTE(hotsnoj @ 7 Dec, 2006 - 05:06 PM) *

What is this interface stuff? Remember, PHP outputs data (in this case HTML) and so "submit_config.php" needs to output whatever interface the user has selected.


are you asking about the array??? $interface[x][y] is an array...submit_config will save all the changes made into a text file...i need the drop down menu to change the details depending on the interface chosen without pressing a go button or such...don't know if that clears it up...

User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Drop Down Menu Problem
18 Dec, 2006 - 12:26 AM
Post #4

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
I'm still having the problem...so anybody...help????
ok...so i'm putting up a bump...but i need the help...
User is offlineProfile CardPM
+Quote Post

snoj
RE: Drop Down Menu Problem
18 Dec, 2006 - 09:58 AM
Post #5

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
Oh so you just want to form to auto-submit when a value is selected from the list. I thought you were having problems with submitting the data outputting what you wanted.

You can add this to each of the <option> tags onSelect="this.form.submit();" and it will submit the form once an option is selected.
User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Drop Down Menu Problem
21 Dec, 2006 - 06:43 AM
Post #6

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
hotsnoj...i tried that and all that happens is that it takes me to the submit_config page.. i don't want to go there...
you see what i need to do is this...

if (for example) option 2 is selected...i want details 1 and details 2 to change to the values of option2.. (the whole array thing)...

this is what i did with the code:
CODE

  
          <form action=[b]"submit_config.php" [/b] method="POST">
            <!-- interfaces option -->    
            <b>Interfaces: </b>
               <select size="1" name="Interface" onChange="this.form.submit();">
<?php
                  for ($i=0;$i<$num_of_interfaces;$i++)
                  {  ?>
                           <option value=<?php echo $interfaces[$i][1]; ?> >
                               <?php echo $interfaces[$i][1];?>
                          </option>
<?php            }  //--end for
                    ?>
                  </select>            
                            
             <br>
                <b>detail1: </b>
<?php       echo $detail1; ?>   //--- this must change depending on which option is                         selected
            <br>
            <b>detail2   : </b>
<?php       echo $detail2; ?>
            <br>            


This post has been edited by Lord Hadies: 21 Dec, 2006 - 06:44 AM
User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Drop Down Menu Problem
21 Dec, 2006 - 06:51 AM
Post #7

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
ok i have a feeling that the last post wasnt clear enough...
once one of the options are selected... i need to pass the variable $i back to the SAME page..the problem right now is that $i keeps its value as 3 because the loop ends at 3. i really have no idea what to do....

User is offlineProfile CardPM
+Quote Post

snoj
RE: Drop Down Menu Problem
21 Dec, 2006 - 09:39 AM
Post #8

Fell off the face of the earth
Group Icon

Joined: 31 Mar, 2003
Posts: 3,325



Thanked: 9 times
Dream Kudos: 750
My Contributions
Your problem is that you don't have any checks in the code to tell it to output anything different. You'll need hooks in there to output the selected="selected" code for the options. You'll also need to use the key for the option selected to change the details.
User is offlineProfile CardPM
+Quote Post

Lord Hadies
RE: Drop Down Menu Problem
8 Jan, 2007 - 12:56 AM
Post #9

D.I.C Regular
***

Joined: 24 Nov, 2006
Posts: 307


My Contributions
well...i've actually finally got what i wanted...
the thing is i realised i didn't need to submit anything to another page hence i made the form point to itself...that helped with the onChange comman (thanx hotsnoj) smile.gif
the next thing i realised was that my VALUES for the interface section were all wrong...so i just gave them values of $i. this then allowed me to submit the number i needed (ie. where in the array i was) smile.gif after that i then changed my function for checking what is selected to the display selected. i also found out that there is no selected="selected" or checked="checked" for the <option> thing...it just needs to print seleced and value it works!!!!

this is the code for the what i wanted smile.gif

CODE


<?php //--- This function shows the details depending on the interface selected
      function give_details($interfaces,$i,&$detail1,&$detail2)
      {
        $detail1=$interfaces[$i][2];
        $detail2=$interfaces[$i][3];
      } //--- end function give_details()
?>
        

<?php //--- This function displays the form
      function show_form($CHECKED1,$CHECKED2,$CHECKED3)
       {
         get_info($num_of_interfaces,$interfaces); ?>
            
          <form action="config.php" method="POST"> <!-- this page is called config.php -->
            <!-- interfaces option -->    
<?php   $num=$_REQUEST['Interface']; ?>
           <b>Interfaces: </b>
                
                 <select size="1" name="Interface" onchange=this.form.submit()>
<?php
                  for ($i=0;$i<$num_of_interfaces;$i++)
                  {  ?>
                           <option value=<?php echo $i; ?> <?php echo check_selected($num,$i);?>  >
                               <?php echo $interfaces[$i][1];?>
                          </option>
<?php            }  //--end for
                    ?>
                  </select>            
                            
             <br>
                <b>detail1: </b>
<?php       echo $detail1; ?>
            <br>
            <b>detail2   : </b>
<?php       echo $detail2; ?>
            <br>            
             <br>
             <br>
           </form>
<?php } ?> <!-- End of Function show_form() -->




THanx for the help hotsnoj smile.gif it was really appriciated and with your help i worked out this problem... case closed.

ok now to create another problem smile.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/8/09 08:56PM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month