Passing drop down list variable to php without submit button

Discussion in 'JavaScript' started by jacka, Jul 21, 2008.

  1. #1
    Hi
    I have a simple drop down list.
    upon user choosing an option I wish to refresh the same page and pass that chosen value to php. without using submit button

    I am new to php and even newer to php.

    can anyone please help.
    This is my code.
    how.

    
    <SELECT NAME="countries" SIZE="1"
    ONBLUR="if (selectedIndex > 0) { text.value = item(selectedIndex).value;window.location.reload(); }"
    >
                              <OPTION VALUE="Please select country">Please select country</OPTION>
                              <OPTION VALUE="Argentina">Argentina</OPTION>
                              <OPTION VALUE="Australia">Australia</OPTION>
                              <OPTION VALUE="Austria">Austria</OPTION>
    Code (markup):
    .....
    </SELECT>


    I have found this snippet that I think I should use but don't know how

    Make your java call the php script with something like

    yourscript.php3?var1=value1&var2=value2

    and you will access $var1 and $var2 in your php script.:

    Thanks for your time.
    p.s. I have this question listed in php, but I think this is a javascript question really.
     
    jacka, Jul 21, 2008 IP
  2. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Hi
    So far I have managed to get the value of the chosen list using this script:
    
    <script type="text/javascript">
    	function showSelected(val){
    		document.getElementById
    ('selectedResult').innerHTML = "The selected number is - " 
    + val;
    	}
    </script>
    
    <div id='selectedResult'></div>
    
    <select name='test' onChange='showSelected(this.value)'>
    	<option value='1'>one</option>
    	<option value='2'>two</option>
    </select>
    
    Code (markup):
    Now what I need to do is using refresh or hidden form pass the value to the php.
    Easier said that done.
    Any ideas please guys.
    :confused::confused:
     
    jacka, Jul 21, 2008 IP
  3. jacka

    jacka Peon

    Messages:
    165
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    0