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
    Aug 2011
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Need to search input text for a number of different words

    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.

    Thanks!!

  • #2
    New to the CF scene
    Join Date
    Aug 2011
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Just threw together something that should handle what you're after.
    Hope this helps!

    Code:
    <html>
    	<head>
    		<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");
    			}
    		</script>
    	</head>
    	
    	<body>
    		<input type="text" id="ingredients"></input>
    		<input type="button" value="Search for silicones or sulfates" onClick="search(document.getElementById('ingredients').value)">
    	</body>
    </html>

  • #3
    Banned
    Join Date
    Feb 2011
    Posts
    2,699
    Thanks
    13
    Thanked 395 Times in 395 Posts
    This is the the same question as you posted in this thread.

    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.
    Last edited by bullant; 08-13-2011 at 03:08 PM.


  •  

    Posting Permissions

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