Pourquoi avez-vous besoin d'utiliser jQuery? Je voudrais simplement utiliser JavaScript et AJAX.
Utilisez ce HTML
<select onchange="updatePage(this.value)">
<option value="AL">Alabama</option>
<option value="AK">Alaska</option>
<option value="AZ">Arizona</option>
...etc...
</select>
<div id="content">State-Specific Page Content Goes here</div>
Ce Javascript
function updatePage(selectedState){
//Create Ajax Object
var ajax= getXmlObject();
//Compose URL to fetch state content
//if html names are StateContentNY.html, StateContentAK.html, etc..
var url= 'StateContent' + selectedState + '.html';
//If Ajax Object is ready...
if (ajax.readyState == 4 || ajax.readyState == 0) {
//Post the URL
ajax.open("POST", url, true);
//set some loading text so the user knows content is downloading
document.getElementById('content').innerHTML='Loading... Please wait';
//Alternately, you could pop an animated gif in there.
//document.getElementById('content').innerHTML='<img src="images/loading.gif" />';
//Define what happens when the ajax state changes
ajax.onreadystatechange = function (x){
//if state is 4 (Finished)
if (ajax.readyState == 4) {
//Get Response Text (This sample assumes it's HTML)
var a = ajax.responseText;
//put HTML in the div with the id "Content"
document.getElementById('content').innerHTML=a;
}
};
ajax.send(null);
}
}
function getXmlObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest();
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP");
} else {
showError('Status: Cound not create XmlHttpRequest Object. Consider upgrading your browser.','Please Wait');
}
}
Ensuite, votre la page getStateContent.php obtiendrait la valeur de l'état en appelant $ _REQUEST [ 'Etat']. Une fois que la page PHP connaît l'état utilisé, il peut afficher des liens vers les fichiers PDF appropriés.
Cela fonctionne très bien, mais quand je change à nouveau le menu déroulant, il ne supprime pas la première option sélectionnée. i ajusté le jquery à ceci: $ ('# stateselector') modifier (function() { \t $ ('statecontent. ') hide(); \t $ (' #' + $ (this)... val()). fadeIn(); \t \t}); }); –
Merci. Je viens de modifier ma réponse pour inclure votre solution. –