Drop Down Menu Problem

Can't refresh values when i select an item from a drop down menu

Page 1 of 1

8 Replies - 2803 Views - Last Post: 08 January 2007 - 01:56 AM

#1 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Drop Down Menu Problem

Posted 07 December 2006 - 03:30 AM

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
<?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 :) )

Is This A Good Question/Topic? 0
  • +

Replies To: Drop Down Menu Problem

#2 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Drop Down Menu Problem

Posted 07 December 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.
Was This Post Helpful? 0
  • +
  • -

#3 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Re: Drop Down Menu Problem

Posted 11 December 2006 - 01:51 AM

View Posthotsnoj, on 7 Dec, 2006 - 05:06 PM, said:

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...
Was This Post Helpful? 0
  • +
  • -

#4 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Re: Drop Down Menu Problem

Posted 18 December 2006 - 01:26 AM

I'm still having the problem...so anybody...help????
ok...so i'm putting up a bump...but i need the help...
Was This Post Helpful? 0
  • +
  • -

#5 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Drop Down Menu Problem

Posted 18 December 2006 - 10:58 AM

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.
Was This Post Helpful? 0
  • +
  • -

#6 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Re: Drop Down Menu Problem

Posted 21 December 2006 - 07:43 AM

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:
  
		  <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 December 2006 - 07:44 AM

Was This Post Helpful? 0
  • +
  • -

#7 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Re: Drop Down Menu Problem

Posted 21 December 2006 - 07:51 AM

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....
Was This Post Helpful? 0
  • +
  • -

#8 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: Drop Down Menu Problem

Posted 21 December 2006 - 10:39 AM

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.
Was This Post Helpful? 0
  • +
  • -

#9 Lord Hadies  Icon User is offline

  • D.I.C Regular

Reputation: 0
  • View blog
  • Posts: 307
  • Joined: 24-November 06

Re: Drop Down Menu Problem

Posted 08 January 2007 - 01:56 AM

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) :)
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) :) 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 :)


<?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 :) it was really appriciated and with your help i worked out this problem... case closed.

ok now to create another problem :)
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1