Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Help on splitting string for search...

    Hi I am trying to split the string from a text input to search a database. I will like my visitors to type a string of words on a single field and from there search all the fields of the database.

    This is what I have so far...

    This is the form page
    Code:
     <html>
    
    <head>
    <meta name="GENERATOR" content="Microsoft FrontPage 6.0">
    <meta name="ProgId" content="FrontPage.Editor.Document">
    <meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
    <title>New Page 1</title>
    <script type="text/javascript" language="javascript"  src="buscarsplit.js" >
    </script>
    <meta name="Microsoft Border" content="t, default">
    </head>
    
    <body  >&nbsp;
    
    <a href="#" onclick="splitbuscar2('1 2 3 4 5 6 7 8 9')">go</a>
    
    <form name="la_forma" onsubmit="splitbuscar2(window.document.la_forma.box.value);return alert('por fin!!!')" method="POST" action="splitgood3.htm">
    
    <input type="text" name="box">
    <input type="hidden" name="box0" value=voy>
    <input type="submit" name="su">
    </form>
    
    
    </body></html>
    this is the function saved on a .js file
    Code:
    function splitbuscar2(fromm)
    
    {
    var box0;var box1;var box2;var box3;var box4;var box5;var box6;var box7;var box8;var box9;var box10;
    
    var lista_campos = 
    	new Array("box0","box1","box2","box3","box4","box5","box6","box7","box8","box9","box10");
    
    alert(lista_campos);
    alert(fromm);
    var num_ele = 0;
    var array_buscar = fromm.split(" ");
    num_ele = array_buscar.length;
    
    for (var count = 0; count < num_ele; count++)
    {alert(" poss:" + array_buscar[count]);
    
    alert("counter" + count);
    window.document.write(array_buscar[count]);
    lista_campos[count] = array_buscar[count];
    window.document.write("b " + lista_campos);
    alert("box:" + lista_campos[count]);
    var voy = lista_campos[2];
    }
    return voy;
    }
    Here the script ends...

    Please disregard all the alerts and writings. Just used for tracking values.

    Thanks.
    Last edited by Kor; 09-05-2008 at 03:02 PM. Reason: wrap the code [code][/code]

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,146
    Thanks
    203
    Thanked 2,547 Times in 2,525 Posts
    I am not entirely sure that I understand, but I think that you want to use the string.split() method:-

    Code:
    <script type = "text/javascript">
    var txt ="The quick brown fox jumps over the lazy dog";
    var txtArray = txt.split(" ");
    alert (txtArray);
    </script>

    Seen in the classified ads: Nice parachute - never opened - used once.
    Last edited by Philip M; 09-06-2008 at 06:33 PM. Reason: Typo

  • #3
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    I am not entirely sure that I understand, but I think that you want to use the string.split() method:-

    Code:
    <script type = "text/javascript">
    var txt ="The quick brown fox jumps over the lazy dog";
    var txtArray = txt.split(" ");
    alert (txtArray);
    </script>

    Seen in the classified ads: Nice parachute - never opened - used once.
    What I need to bring those results back to a form to search a database. I want to make a kind of super query of a database using a single text box input.

    I you write in a text box(for search) "toyota tacoma 2005". I want to split this into "toyota" "tacoma" "2005". then run a query like this:

    WHERE field1 LIKE ('%ARRAY[0]%'
    OR field2 LIKE '%ARRAY[0]%'
    OR field3 LIKE '%ARRAY[0]%'
    OR field4 LIKE '%ARRAY[0]%'
    OR field1 LIKE '%ARRAY[1]%'
    OR field2 LIKE '%ARRAY[1]%'
    OR...and so on...

    I know how to split the string. What I need is to how to assigned those values to a hidden input on a search form...

    thank


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •