[JavaScript/PHP] Dynamische search

Pagina: 1
Acties:

  • Guru Evi
  • Registratie: Januari 2003
  • Laatst online: 23-12-2025
Ik wil een dynamische search maken die automatisch de data invult van bepaalde velden in een form. Ik kan wel degelijk het PHP script maken maar ik ben niet goed in JavaScript

Ik heb nu het volgende:

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
function goSearch() {
    var string = document.getElementById('name').value;

    var xmlhttp=false;
    var results=false;
    /*@cc_on @*/
    /*@if (@_jscript_version >= 5)
    // JScript gives us Conditional compilation, we can cope with old IE versions.
    // and security blocked creation of the objects.
    try {
         xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
    } catch (e) {
        try {
            xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
        } catch (E) {
            xmlhttp = false;
        }
    }
    @end @*/
    if (!xmlhttp && typeof XMLHttpRequest!='undefined') {
            try {
                    xmlhttp = new XMLHttpRequest();
            } catch (e) {
                    xmlhttp=false;
            }
    }
    if (!xmlhttp && window.createRequest) {
        try {
            xmlhttp = window.createRequest();
        } catch (e) {
            xmlhttp=false;
        }
    }
    
    xmlhttp.open("GET", "/pages/frontend/search_all_assoc.php?"+string ,true);
    xmlhttp.onreadystatechange=function() {
        if (xmlhttp.readyState==4) {
            results = (xmlhttp.responseText)
        }
        var option = new Option(results,1);
            document.univ.dynfill.options[1] = option;
    }
 xmlhttp.send(null)


Maar dat doet niet veel. De bedoeling is dus zodra iemand 4 of meer karakters invult van de naam, dat het script dan gaat zoeken in de database en alles begint te zoeken die erop lijkt (5000 records - doe ik in MySQL met Soundexes en like '%string%') en deze in een aparte dropdown weergeeft. Daarnaast moet eenmaal het resultaat geselecteerd wordt ook het adres en nog enkele andere velden ingevuld worden.

Ik probeer dit door het volgende te doen:
<INPUT name="name" type="text" onchange="goSearch()">
<select name="dynfill"></select>

Zou iemand mij op weg kunnen helpen, ik heb proberen zoeken maar vind niet direct iets dat ik kan gebruiken. Daarnaast moet het ook op alle platformen werken (Safari, Firefox, IE)

Pandora FMS - Open Source Monitoring - pandorafms.org


  • Creepy
  • Registratie: Juni 2001
  • Laatst online: 11:39

Creepy

Tactical Espionage Splatterer

"I had a problem, I solved it with regular expressions. Now I have two problems". That's shows a lack of appreciation for regular expressions: "I know have _star_ problems" --Kevlin Henney


  • Rhapsody
  • Registratie: Oktober 2002
  • Laatst online: 08:46

Rhapsody

In Metal We Trust

🇪🇺 pro Europa! | Puinhoop Veroorzaken en Vertrekken (PVV)


  • funkwurm
  • Registratie: December 2005
  • Laatst online: 22-02-2021
moet hier:
JavaScript:
1
xmlhttp.open("GET", "/pages/frontend/search_all_assoc.php?"+string ,true);

niet de naam van de sleutel in $_GET komen te staan? :Y)
JavaScript:
1
xmlhttp.open("GET", "/pages/frontend/search_all_assoc.php?suggest="+string ,true);

  • XWB
  • Registratie: Januari 2002
  • Niet online

XWB

Devver
Klopt, via GET moet je alles in de url meegeven.
results = (xmlhttp.responseText)
Moeten we toch even weten hoe die output eruit ziet.
var option = new Option(results,1);
document.univ.dynfill.options[1] = option;
Dit klopt ook niet. Je wil sowieso meerdere options, dus hier moet een lus komen. Persoonlijk zou ik de resultaten via XML laten terugkomen en de options via het DOM laten maken en dan toevoegen aan je select.
(5000 records - doe ik in MySQL met Soundexes en like '%string%') en deze in een aparte dropdown weergeeft.
En als je nou 1000 results hebt wil jij die in een select gaan stoppen ? :p

[ Voor 19% gewijzigd door XWB op 17-04-2006 15:55 ]

March of the Eagles