azedor Opublikowano 15 Maja 2006 Zgłoś Opublikowano 15 Maja 2006 (edytowane) Mam pytanie, czy mogą jakś w skrypcie napisanym w java scripcie odowłać się do bazy danych ? Np chcialbym w java scipricie zrobić tablicę ktorej elementami są odpowiednio pola z mojej bazy danych. Cyz woogle w java scipt może mieć dostęp do bazy danych ? chyba udało mi się już znaleźć to czego szukałem: Tutaj umieszczam ten skrypt dzięki któremu mogą zrobić dynamicznego selecta, tzn mam 2 selecty, w I wybieram jakąś opcje(np grupe) i automatycznie bez odświeżania stronki do drugiego selecta mi się ładują odpowiednie podgrupy. wprawdzie poniższy skrypt nie korzysta jesce z bazy danych, ale jak ktoś wie o co chodzi to go bez problemu przerobi tak żeby korzystał, ja już swój przerobilem i mi działa. <html> <body> <? echo"<form method='get' action='index.php'> <select name='grupa' id='pda-brand'> <option value='select'>Select PDA brand...</option> <option value='dell'>Dell</option> <option value='hp'>HP</option> <option value='palmone'>PalmOne</option> </select> <select name='podgrupa' id='pda-type'> <option class='select' value='select'>Select PDA type...</option> <option class='dell' value='aximx30'>Axim X30</option> <option class='dell' value='aximx50'>Axim X50</option> <option class='hp' value='ipaqhx2750'>iPAQ hx2750</option> <option class='hp' value='ipaqrx3715'>iPAQ rx3715</option> <option class='hp' value='ipaqrz1710'>iPAQ rz1710</option> <option class='palmone' value='tungstene2'>Tungsten E2</option> <option class='palmone' value='tungstent5'>Tungsten T5</option> <option class='palmone' value='zire72'>Zire 72</option> </select> <input type='submit' name='send' value='wyslij'> </form>"; ?> <script> function dynamicSelect(id1, id2) { // Feature test to see if there is enough W3C DOM support if (document.getElementById && document.getElementsByTagName) { // Obtain references to both select boxes var sel1 = document.getElementById(id1); var sel2 = document.getElementById(id2); // Clone the dynamic select box var clone = sel2.cloneNode(true); // Obtain references to all cloned options var clonedOptions = clone.getElementsByTagName("option"); // Onload init: call a generic function to display the related options in the dynamic select box refreshDynamicSelectOptions(sel1, sel2, clonedOptions); // Onchange of the main select box: call a generic function to display the related options in the dynamic select box sel1.onchange = function() { refreshDynamicSelectOptions(sel1, sel2, clonedOptions); }; } } function refreshDynamicSelectOptions(sel1, sel2, clonedOptions) { // Delete all options of the dynamic select box while (sel2.options.length) { sel2.remove(0); } // Create regular expression objects for "select" and the value of the selected option of the main select box as class names var pattern1 = /( |^)(select)( |$)/; var pattern2 = new RegExp("( |^)(" + sel1.options[sel1.selectedIndex].value + ")( |$)"); // Iterate through all cloned options for (var i = 0; i < clonedOptions.length; i++) { // If the classname of a cloned option either equals "select" or equals the value of the selected option of the main select box if (clonedOptions.className.match(pattern1) || clonedOptions.className.match(pattern2)) { // Clone the option from the hidden option pool and append it to the dynamic select box sel2.appendChild(clonedOptions.cloneNode(true)); } } } // Attach our behavior onload window.onload = function() { dynamicSelect("pda-brand", "pda-type"); } </script> </body> </html> Edytowane 15 Maja 2006 przez azedor Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...
PelzaK Opublikowano 16 Maja 2006 Zgłoś Opublikowano 16 Maja 2006 javascript działa po stronie klienta.. przeglądarki.. więc Twoja przeglądarka musiała by mieć dostęp do bazy danych, która znajduje się gdzieś na jakimś serverze... Cytuj Udostępnij tę odpowiedź Odnośnik do odpowiedzi Udostępnij na innych stronach Więcej opcji udostępniania...