Welcome!

Welcome to the official BlackBerry Support Community Forums.

This is your resource to discuss support topics with your peers, and learn from each other.

inside custom component

Web and WebWorks Development

Reply
Highlighted
New Contributor
Posts: 2
Registered: ‎07-05-2011
My Device: Bold
My Carrier: Developer

how to do Javascript/XML based search using XMLHTTP RSS

Hai friend

i tryed this please check this code and resolve my bugs

<html>
<script language="javascript" type="text/javascript">
        if (window.XMLHttpRequest) {// code for IE7+, Firefox, Chrome, Opera, Safari
        xmlhttp = new XMLHttpRequest();
    }
    else {// code for IE6, IE5
        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
    }
    xmlhttp.open("GET", "index.xml", false);
    xmlhttp.send();
    xmlDoc = xmlhttp.responseXML;
    var x;
      var y = 0;
     x = xmlDoc.getElementsByTagName("Search");      
    
        function searchIndex()
        {             
            // get the search term from a form field with id 'searchme'
            results = new Array;
            var searchterm = document.getElementById("searchme").value;
            
 
            if (searchterm == null || searchterm == "")
            {
                alert("Enter at least three characters");
                return false;
            }
 
            if (isNaN(searchterm))
             {
 
                    alert("Enter numberic value only");
                    false;
 
             }
 
                var istrlen = searchterm.length;                
                var tempname;
 
                if (istrlen == 1) {
                    
                    tempname =  searchterm;
                }
 
                if (istrlen == 2) {
                    
                    tempname = searchterm;
                }
 
                if (istrlen == 3) {
                    
                    tempname =  searchterm;
                }
 
              
            for (i = 0; i < x.length; i++)
            {    
                    // see if the XML entry matches the search term,
                    // and (if so) store it in an array
                var name = x[i].childNodes[0].firstChild.nodeValue;
                                
 
                    //var lnkname = x[i].childNodes[0].firstChild.nodeValue;
                    //alert(lnkname);                    
                    //var exp = new RegExp(searchterm, "i");
                var res = name.search(tempname);
            
                    if (res >= 0)
                    {
                        y = y + 1;   
                            
                        results.push(name);            
                        
                        document.write(name + "<br />");
 
 
                     }
                }
            }  
             
        
 
        function test(name, lnkname)
        {
           
            document.write('<table border="0" style="width:100%">');
            for (var i = 0; i < x.length; i++)
           {       
        //var sear=x[i].childNodes[0].firstChild.nodeValue //+ x[i].childNodes[0].firstChild.nodeValue;    
            document.write("<tr onclick='displayInfo(" + i + ")'>");            
            document.write('<td>' + x[i].childNodes[0].firstChild.nodeValue + '</td>');
            document.write('</tr>');
            }
        //document.getElementById("show").innerHTML = sear;
            document.write('<table>');
            document.close();
        }    
    
 
        //
    </script>
 
</head>
<body>
    <input id="searchme" type="text" size="20">&nbsp;&nbsp;<input type="button" value="Search" onclick="searchIndex(); return false;" />
 
 
<div id="show"></div>
</body>
</html>