javascript - Accessing a variable from inside a jquery drop down list? -
i have jquery dropdown list has 2 dropdowns. first 1 list of cars , second 1 shows car's models. working fine. use selection selected user search database (mysql) , find specific element within database. gives me else within code , once gave me undefined variable error message.
can please me learn how code can access variables , display search result? here code:
this example of jquery i'm using - i'm using cars shows cities:
<select class="select" id="province" onchange="filtercity();"> <option value="1">rm</option> <option value="2">fi</option> </select> <select class="select" id="city" disabled> <option data-province="rm" value="1">roma</option> <option data-province="rm" value="2">anguillara sabazia</option> <option data-province="fi" value="3">firenze</option> <option data-province="fi" value="4">pontassieve</option> </select> <span id="option-container" style="visibility: hidden; position:absolute;"></span> <script> function filtercity(){ var province = $("#province").find('option:selected').text(); // stores province $("#option-container").children().appendto("#city"); // moves <option> contained in #option-container <select> var tomove = $("#city").children("[data-province!='"+province+"']"); // selects city elements move out tomove.appendto("#option-container"); // moves city elements in #option-container $("#city").removeattr("disabled"); // enables select }; </script>
and here code i'm trying access searched variable (this code echoing wrong (the else): used name="car" in second select.
if (isset($_post['car'])) { $_session['car'] = $_post['car']; $car = $_session['car']; } function find_tire(){ if (isset($_post['car'])) { $_session['car'] = $_post['car']; $car = $_session['car']; } global $db; if (isset($car)) { $query = $db->prepare("select idtires vehicle idcarmodel = $car"); $query->execute(); $tire = $query->fetchall(); var_dump($query);} if (isset($tire)) { echo "<ul>"; foreach ($tire $name) { echo "<li id='tiresearch'>"; echo "tire size available: " . $name ['idtires']; echo "</li>"; }echo "</ul>"; } else { echo "wrong"; } }
you can use ajax send variable page , response there .something
var id = $('selector').val(); var ajaxurl = 'http://example.com'; var data = id; $.ajax({ type: "post", url: ajaxurl, data: {data: data}, success: function(result) { window.console.log('successful'); } });
Comments
Post a Comment