Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

arrays for questions

Status
Not open for further replies.

garms

Technical User
Aug 10, 2000
1
US
I found a script that would be great for what I want to do on a humane society page that I make, But... I don't know how to make an array for it to pop up an answer to a question from a text box with onclick.<br><br>The one below does exactly what I want except I need to put an array for specific questions and words.<br>example of what I am looking for:<br>If you type &quot;I want to adopt a dog&quot; <br>I would like it to come up &quot;What kind of a dog are you looking for?&quot;<br><br>Would javascript be able to do this?<br>Below is the program I found:<br><br>&lt;script type=&quot;text/Javascript&quot;&gt;&lt;!--<br>function filter(el) {<br>&nbsp;&nbsp;&nbsp;&nbsp;var j = 0;<br>&nbsp;&nbsp;&nbsp;&nbsp;var strHTML = &quot; &quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;var v_foundarray =&nbsp;&nbsp;new Array();<br>&nbsp;&nbsp;&nbsp;&nbsp;var v_array = new Array(&quot;What kind of dog?&quot;,&quot;What kind of cat?&quot;,&quot;123&quot;,&quot;324&quot;,&quot;34324&quot;,&quot;565&quot;);<br>&nbsp;&nbsp;&nbsp;&nbsp;var v_regexp = new RegExp(el.value,&quot;gi&quot;);<br><br>&nbsp;&nbsp;&nbsp;&nbsp;for ( var i = 0; i &lt; v_array.length; i++ ) {&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;if ( v_regexp.exec(v_array<i>) ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;v_foundarray[j] = v_array<i>; // Pattern found<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;j++;<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;for ( var k = 0; k &lt; v_foundarray.length; k++ ) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;strHTML += v_foundarray[k] + &quot;&lt;br&gt;&quot;;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br><br>&nbsp;&nbsp;&nbsp;&nbsp;if (document.all) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.all.vals.innerHTML = strHTML;<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>&nbsp;&nbsp;&nbsp;&nbsp;else if (document.layers) {<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.layers['vals'].document.open();<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.layers['vals'].document.write(strHTML);<br>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;document.layers['vals'].document.close();<br>&nbsp;&nbsp;&nbsp;&nbsp;}<br>}<br>//--&gt;&lt;/script&gt;<br><br>&lt;form onSubmit=&quot;return false&quot;&gt;<br>&lt;input name=&quot;test&quot; type=&quot;text&quot;&gt; &lt;input type=&quot;button&quot; value=&quot;Filter&quot; onClick=&quot;filter(this.form.test)&quot;&gt;<br>&lt;/form&gt;<br><br>&lt;div id=&quot;vals&quot; style=&quot;position:absolute&quot;&gt;<br>&lt;pre&gt;<br><br><br><br><br>&lt;/pre&gt;<br>&lt;/div&gt;<br><br><br><br><br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top