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 biv343 on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Help modifiying this script 1

Status
Not open for further replies.

buzzybee

Programmer
May 23, 2001
17
US

i like this script, but i need it to be triggered on a button click...for instance, instead of the prompt being triggered by the onfocus, i would like to have a button next to the drop down list that says, "Search this menu for" with an onclick event...but i am not sure how to make this work...
any suggestions?
TIA
Amanda :)
 
First off, that is one of the worst pieces of coding I have ever seen, no offense to the author. Secondly, to fix it to act as you want, remove all the on focus stuff and put a button next to it like so:

<select name=menu1 size=1>
<!--all the options-->
</select>
<input type=&quot;button&quot; onclick=&quot;promptSearch(this.form.name, this.form.menu1.name)&quot;>

I think that'll do what u want, but you may want to try out my ComboBox widget instead. Kinda acts like the address bar of IE, but only works in IE5+

jared@eae.net -
 
First off, I love your combo box! this is what i really wanted to use :( but unfortunately..it seems impossible...I am using Visual fox pro and a program called web connection to build those dropdown lists(they are the results of a SELECT statement from a database)....and i would have no idea how to use both of them.....I am trying to rig something to make this work.....grrrr...

i copied the code into the header, and placed
Code:
<input type=&quot;button&quot; onclick=&quot;promptSearch(this.form.name, this.form.txtstudent.name)&quot;>
next to my dropdown,
Code:
<SELECT NAME=&quot;txtstudent&quot; SIZE=&quot;1&quot;><OPTION>...

i am getting this error:
line 19
document.forms[...].elements is not an object
it is this line:
Code:
for (var j = 0; j < document.forms[thisform].elements.length; j++) {


what did i do wrong?
TIA
Amanda
 
hmmmm... wish I had more time you with the server-side generation of ComboBox options.

I'm not sure what's wrong with the code you are using, but I will write you a new version of it. I tested it in IE5.5:

<script>

function searchPrompt(obj)
{
var rsp = prompt(&quot;Enter a value to search for.&quot;,&quot;&quot;);
if(rsp) obj.value = rsp.toUpperCase();
}

</script>

<form name=&quot;amandasform&quot;>
<select name=&quot;thebox&quot;>
<option value='a1'>a1</option>
<option value='a2'>a2</option>
<option value='a3'>a3</option>
</select><input type=&quot;button&quot; onclick=&quot;searchPrompt(this.form.thebox)&quot;>
</form>
jared@eae.net -
 
i copied this into my head
<script>
function searchPrompt(obj)
{
var rsp = prompt(&quot;Enter a value to search for.&quot;,&quot;&quot;);
if(rsp) obj.value = rsp.toUpperCase();
}

</script>
then added this to my button
<input type=&quot;button&quot; value=&quot;Search this menu&quot; onclick=&quot;searchPrompt(this.form.txtstudent)&quot;>
i dont get an error, but when i type in a know value i dont get any results?
Sorry to be such a pest

Amanda
 
I think if you change the option values to uppercase it will work.
i.e. change a1 to A1, etc...
 
On second thought it might be easier to change the last line of the function to:

if(rsp) obj.value = rsp;
 
i must be totally goofing this up, i stil dont get any results....
Amanda
 
Amanda-
Here's an example using jaredn's script and what you posted before. It works in Netscape 6 and IE5.5, but not in Netscape 4.

<html>
<head>
<script>
function searchPrompt(obj)
{
var rsp = prompt(&quot;Enter a value to search for.&quot;,&quot;&quot;);
if(rsp) obj.value = rsp;
}

</script>
</head>
<body>
<form>
<select name=&quot;txtstudent&quot;>
<option value='a1'>a1</option>
<option value='a2'>a2</option>
<option value='a3'>a3</option>
</select>
<input type=&quot;button&quot; value=&quot;Search this menu&quot; onclick=&quot;searchPrompt(this.form.txtstudent)&quot;>
</form>
</body>
</html>
 
oh well. i copied and pasted that code word for word and i get no search results, even just typing in a2... i have IE 5........
Amanda
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top