Have javascript right, but need to pass variable with ajax, WILL GIVE REP! function showBox() { var selectBox = document.getElementById("store").value; if (selectBox == 'N') { document.getElementById("penyard").style.display="none"; }else{ document.getElementById("penyard").style.display="block"; } } Code (markup): so how do I pull the value of selectBox to php without refreshing the page. penyard needs the value of selectBox to know what to display
Have a look at AJAX with jQuery (http://api.jquery.com/jQuery.ajax/) Load up the jquery library Then some code like this will sort you out: function showBox() { // Set selectBox variable based on #store value $selectBox = $("#store").val(); // Show & Hide if ($selectBox == 'N') { $("#penyard").css('display', 'none'); } else{ $("#penyard").css('display', 'block'); } // Send data to PHP script via AJAX $.ajax({ url: "path-to-your-php-script.php", type: "POST", data: {selectbox: $selectBox}, success: function() { // Anything you want to happen on success here } }); } Code (markup): In your php script you just need to get the content of $_POST['selectbox']; Hope this helps (have not tested syntax)
I figured it out for the create a new feature using a method similar to this (yes used the POST)... But to edit a item using this its hard because onLoad doesnt work in <select> / <option> environments... Where when creating new its just OnChange if I remember right.
Please can you clarify what you mean? Do you mean you can't conrol whatever #penyard is? If not it is probably because it need to be added to the DOM (http://api.jquery.com/bind/)
I will advise learning jQuery if you would like to work with AJAX as the two go hand in hand and are seemingly easier than pure javascript using XMLHttpRequest to use AJAX.