...

View Full Version : Help on splitting string for search...



kompay
09-05-2008, 01:57 PM
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


<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


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.

Philip M
09-06-2008, 06:20 PM
I am not entirely sure that I understand, but I think that you want to use the string.split() method:-


<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.

kompay
09-06-2008, 08:51 PM
I am not entirely sure that I understand, but I think that you want to use the string.split() method:-


<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



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum