Announcement

Collapse
No announcement yet.

drop down box: get selected value to php script

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

  • drop down box: get selected value to php script

    Hello,

    I'm still struggling with my website, more specifically with the PHP script. I'm now trying to get the PHP script to read a value from a drop down box. There are 2 drop down boxes, where the value of the first determines the vales in the second one (it is to select hour and minutes). This part works.

    I currently have this in the header of the HTML file:
    Code:
    <SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
        //	Initialize class for Type and Style
    	function Uur(id, uur){
    		this.id = id; this.uur = uur;
    	}
    	function Min(id, id_uur, min){
    		this.id = id; this.id_uur = id_uur;	this.min = min;
    	}
    
        //	uren definieren
    	UurArray = new Array(
    			new Uur(1, "9"),
    			new Uur(1, "10"),
    			new Uur(1, "11"),
    			new Uur(2, "12"),
    			new Uur(1, "14"),
    			new Uur(1, "15"),
    			new Uur(1, "16"),
    			new Uur(1, "17"),
    			new Uur(2, "18"));
        //	minuten definieren
    	MinArray = new Array(
    			new Min(0, 1, "00"),
    			new Min(1, 1, "05"),
    			new Min(2, 1, "10"),
    			new Min(3, 1, "15"),
    			new Min(4, 1, "20"),
    			new Min(5, 1, "25"),
    			new Min(6, 1, "30"),
    			new Min(7, 1, "35"),
    			new Min(8, 1, "40"),
    			new Min(9, 1, "45"),
    			new Min(10, 1, "50"),
    			new Min(11, 1, "55"),
    			new Min(0, 2, "00"),
    			new Min(1, 2, "05"),
    			new Min(2, 2, "10"),
    			new Min(3, 2, "15"),
    			new Min(4, 2, "20"),
    			new Min(5, 2, "25"));
    
    	function time_init(sel_uur, sel_min){
    		document.form1.id_uur.options[0]= new Option("uur");
    		document.form1.id_min.options[0]= new Option("min");
    		for(i = 1; i <= UurArray.length; i++){
    			document.form1.id_uur.options[i] = new Option(UurArray[i-1].uur, UurArray[i-1].id);
    			if(UurArray[i-1].id == sel_uur)
    				document.form1.id_uur.options[i].selected = true;
    		}
    		ChangeMin(sel_min);
    	}
    
    	function ChangeMin(sel_min){
    		sel_uur_index = document.form1.id_uur.selectedIndex;
    		sel_uur_value = parseInt(document.form1.id_uur[sel_uur_index].value);
    		for(i = document.form1.id_min.length - 1; i > 0; i--)
    			document.form1.id_min.options[i]= null;
    		j=1;
    		for(i = 1; i <= MinArray.length; i++){
    			if(MinArray[i-1].id_uur == sel_uur_value){
    				document.form1.id_min.options[j]= new Option(MinArray[i-1].min, MinArray[i-1].id);
    				if(MinArray[i-1].id == sel_min)	document.form1.id_min.options[j].selected = true;
    				j++;
    			}
    		}
    	}
    This is in the form definition:
    Code:
    <select name="id_uur" id="id_uur" size="1" style="" onChange="ChangeMin()" onblur="return CheckUur()"></select>
    <select name="id_min" id="id_min" size="1" style="" onblur="return CheckUur()"></select>
    And this is in the PHP script:
    Code:
    $id_uur = $_REQUEST['id_uur'] ;  
    $id_min = $_REQUEST['id_min'] ;
    There are values in the PHP variables, for the hours it is 1 or 2 (1 for 9,10,11,14,15,16,17; 2 for 12,18); for the minutes it is the index of the item in the list.

    How can I get the value that is selected in the dropdownbox in my PHP script (for both the hours and the minutes)?

    Thanks!


    Jörg
    Last edited by VJ; 10 April 2006, 02:14.
    pixar
    Dream as if you'll live forever. Live as if you'll die tomorrow. (James Dean)

  • #2
    Never mind, while typing my question, it hit me.


    edit: nope, it isn't working...

    Jörg
    Last edited by VJ; 8 April 2006, 08:08.
    pixar
    Dream as if you'll live forever. Live as if you'll die tomorrow. (James Dean)

    Comment


    • #3
      I know it has to do with array/attribute addressing, but I don't see it...


      Jörg
      pixar
      Dream as if you'll live forever. Live as if you'll die tomorrow. (James Dean)

      Comment


      • #4
        Any suggestions on how to even get it in Javascript?
        (I can't seem to get the field I want there either)


        Jörg
        pixar
        Dream as if you'll live forever. Live as if you'll die tomorrow. (James Dean)

        Comment


        • #5
          Try hard coding one option in the select boxes and see if it can get that properly. Maybe it's not reading the javascript created options.
          Gigabyte GA-K8N Ultra 9, Opteron 170 Denmark 2x2Ghz, 2 GB Corsair XMS, Gigabyte 6600, Gentoo Linux
          Motion Computing M1400 -- Tablet PC, Ubuntu Linux

          "if I said you had a beautiful body would you take your pants off and dance around a bit?" --Zapp Brannigan

          Comment


          • #6
            It didn't work (or I didn't know how to do it).
            But I have rewritten the functions with some differences in approach, and now it appears to work.


            Jörg
            pixar
            Dream as if you'll live forever. Live as if you'll die tomorrow. (James Dean)

            Comment


            • #7
              I was thinking:

              Code:
              <select name="id_uur" id="id_uur" size="1" style="" onChange="ChangeMin()" onblur="return CheckUur()">
                  <option value="blah">blah</option>
              </select>
              But if you got it working, then nevermind
              Gigabyte GA-K8N Ultra 9, Opteron 170 Denmark 2x2Ghz, 2 GB Corsair XMS, Gigabyte 6600, Gentoo Linux
              Motion Computing M1400 -- Tablet PC, Ubuntu Linux

              "if I said you had a beautiful body would you take your pants off and dance around a bit?" --Zapp Brannigan

              Comment

              Working...
              X