This post has been edited 1 times, last edit by "mopsel" (Aug 15th 2011, 6:53am)
|
|
Cascading Style Sheets |
1 2 3 4 |
select { border: 0px !important; background-color: transparent !important; } |
|
|
JavaScript Code |
1 |
targetSel.options[i++] = new Option( |







|
|
HTML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
<table> <tr> <td id="elem1" style="display:none"> <select name="hauptkategorie" size="5" onchange="sendRequest(this, 'elem2')"> <option value=""></option></select></td> <td id="elem2" style="display:none"> <select name="unterkategorie" size="3" onchange="sendRequest(this, 'elem3')"> <option value=""></option></select></td> <td id="elem3" style="display:none"> <select name="unterunterkategorie" size="3" onchange="sendRequest(this, 'elem4')"> <option value=""></option></select></td> <td id="elem4" style="display:none"> <select name="unterunterkategorie" size="3" onchange="sendRequest(this, 'elem5')"> <option value=""></option></select></td> <td id="elem5" style="display:none"> <select name="unterunterkategorie" size="3" onchange="sendRequest(this, 'elem6')"> <option value=""></option></select></td> <td id="elem6" style="display:none"> <select name="unterunterkategorie" size="1" onchange="sendRequest(this)"> <option value=""></option></select></td> </tr> </table> |
|
|
HTML Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
<div> <div id="elem1" style="display:none; float:left;"> <select name="hauptkategorie" size="5" onchange="sendRequest(this, 'elem2')"> <option value=""></option></select></div> <div id="elem2" style="display:none; float:left;"> <select name="unterkategorie" size="5" onchange="sendRequest(this, 'elem3')"> <option value=""></option></select></div> <div id="elem3" style="display:none; float:left;"> <select name="unterkategorie" size="5" onchange="sendRequest(this, 'elem4')"> <option value=""></option></select></div> <div id="elem4" style="display:none; float:left;"> <select name="unterkategorie" size="5" onchange="sendRequest(this, 'elem5')"> <option value=""></option></select></div> <div id="elem5" style="display:none; float:left;"> <select name="unterkategorie" size="5" onchange="sendRequest(this, 'elem6')"> <option value=""></option></select></div> <div id="elem6" style="display:none; float:left;"> <select name="unterkategorieende" size="5" onchange="sendRequest(this)"> <option value=""></option></select></div> </div> <br style="clear: left;" /> |
|
|
HTML Code |
1 |
... onchange="return sendRequest(this, false, 'success')" |
|
|
JavaScript Code |
1 2 3 4 5 6 7 8 |
function sendRequest(domref, target, success) { if(success) { success = document.getElementById(success); success.style.display = 'block'; } // skip if no target specified if(!target) return false; |
|
|
JavaScript Code |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 |
/** * clears a select form element * * @param targetSel - dom reference to the select element */ function clearSelect(targetSel) { for (var i=targetSel.length; i>=0; i--) { targetSel.options[i] = null; } } /** * sends a request under usage of a loading graphic - targettable has to be positioned relative * * @param srcref - reference to the select element with chosen data * @param target - form element name of target element */ function sendRequest(domref, target) { // skip if no target specified if(!target) return false; // save reference to next target if(domref) domref.followup = target; var req; try { req = window.XMLHttpRequest ? new XMLHttpRequest(): new ActiveXObject("Microsoft.XMLHTTP"); } catch (e) { // no AJAX Support } req.onreadystatechange = function() { if ((req.readyState == 4) && (req.status == 200)) { // merge empty line with response var data = eval('(' + req.responseText + ')'); var targetRef = document.getElementById(target); var targetSel = targetRef.getElementsByTagName('select')[0]; // make it visible targetRef.style.display = 'block'; // clear old data clearSelect(targetSel); // fill with data from json response var i=0; for(var x in data) { targetSel.options[i++] = new Option( data[x].text, data[x].id ); } // clear all followups while(targetSel.followup) { targetRef = document.getElementById(targetSel.followup); // make it hidden targetRef.style.display = 'none'; // mark next select targetSel = targetRef.getElementsByTagName('select')[0]; // clear old data clearSelect(targetSel); } } } req.open('post', 'ajax.php'); req.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded'); // send empty post with initial load req.send(domref !== null ? 'id='+domref.value+'&name='+domref.name : ''); return false; // return false to avoid reload/recentering of the page } |
|
|
HTML Code |
1 2 3 |
<div id="elem2" style="display:none; float:left;"> <select name="unterkategorie" size="5" onchange="sendRequest(this, 'elem3', 'success')"> <option value=""></option></select></div> |
|
|
JavaScript Code |
1 2 3 4 |
if(success) { success = document.getElementById(success); success.style.display = 'block'; } |
Was muss noch in der if Abfrage rein, dass er es auch nur dann aus gibt wenn das Select leer wäre, also die Datenbankanfrage kein Ergebnis zurück gibt ?

|
|
JavaScript Code |
1 2 3 4 5 6 7 8 9 |
function sendRequest(domref, target, success) { if(success) { if(typeof success == 'function') { success(); } else { success = document.getElementById(success); success.style.display = 'block'; } } |
|
|
JavaScript Code |
1 2 3 4 5 6 7 8 9 |
function easyfunc1() { // zeige success success = document.getElementById(success); success.style.display = 'block'; // verstecke die selects selectdiv = document.getElementById('div_um_select'); selectdiv.style.display = 'none'; } |
|
|
HTML Code |
1 |
... onchange="sendRequest(this, 'elem3', easyfunc1)"> |