Hi,
I am trying to get the selected option value and insert into a php variable, without refreshing the page or submitting a button, but only by the on-change event.
Here is what i have done so far after some research though struggling to get it to work.
[B]HTML
[code=html]
<select id=”dropdown1″ class=”select” tabindex=”2″ onchange=”run(this)”>
<option>Select</option>
<option value=”volvo”>Volvo</option>
<option value=”saab”>Saab</option>
<option value=”mercedes”>Mercedes</option>
<option value=”audi”>Audi</option>
</select>
[B]Jquery/Ajax
[CODE]
function run(sel) {
var i = sel.selectedIndex;
if (i != -1) {
//document.getElementById(“car”).value = sel.options[i].text;
$.ajax({
type: “POST”,
url: “home.php”,
data: { car: sel.options[i].text}
}).done(function( msg ) {});
}
}
[B]PHP
[code=php]
if(isset($_POST[“car”])){
$_SESSION[‘car’] = $_POST[“car”];
$myCar = $_SESSION[‘car’] ;
echo $myCar;
}
Again just to clarify the user will select an option from the drop down it will be stored in a php variable to use later down the page for something else. This needs to be done without page refreshing (if possible). If possible provide solution with and without page refresh.
Any help is appreciated,
regards.