View Full Version : Need to search input text for a number of different words

08-02-2011, 10:39 PM
I'm looking to create a simple page where a user can copy and paste a list of ingredients and then push a button to search that list for a number of key words.

Key words:
Amodimethicone, Trimethylsilylamodimethicone, Glycerin, Trideceth-12, Behenoxy, Bisamino, Aminoethyl, PG-Propyl, Phenylpropyl, Methicone, Cyclomethicone, Cyclopentasiloxane, Cyclohexasiloxane, Cyclopentasiloxane, Dimethiconol, Trimethylsiloxysilicate, Silicate, Siloxy, Trimethylolpropane, Diisostearoyl, Copolyol, Dodecylbenzenesulphonate, Diphenyl, silicone, Methicone, Simethicone, Trisiloxane, sulfate, Myreth, Lauryl, Laureth, Sulfonate, dodecylbenzenesulfonate, Xylenesulfonate, Ammonium, Isethionate, Sulfoacetate, Sarcosinate, Sulfosuccinate, Carboxylate, Taurate, glycinate

I don't care how they are alerted if any of the key words match their ingredients pop up, highlight, whatever.

*Incase anyone is wondering it is to search hair products for any form of silcones or sulfates since many people wish to avoid them but they come in many different forms.


08-13-2011, 03:01 PM
Just threw together something that should handle what you're after.
Hope this helps!

<script type="text/javascript">
function search(ingredients)
var keywords = new Array("Amodimethicone", "Trimethylsilylamodimethicone", "Glycerin"); //the rest can be added in the same manner

var amount = 0;
for (var i = 0; i < keywords.length; i++)
if (ingredients.indexOf(keywords[i]) != -1) //If the keyword has been located in the string
alert(keywords[i] + " found at index " + ingredients.indexOf(keywords[i]));
amount += 1;
alert(amount + " keywords were found");

<input type="text" id="ingredients"></input>
<input type="button" value="Search for silicones or sulfates" onClick="search(document.getElementById('ingredients').value)">

08-13-2011, 03:06 PM
This is the the same question as you posted in this thread (http://www.codingforums.com/showthread.php?p=1119467&highlight=ingredients#post1119467).

Why the cross-post?

btw: do you want to do this server or client side - this this is a html/css forum?

Imo this is better done server side, with or without ajax.