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

Calling a Function to Refresh a Select Object on the Same Page 1

Status
Not open for further replies.

c2compliant

Programmer
May 11, 2000
11
0
0
US
I am attempting to create a function which will retrieve a recordset that contains names from a SQL Server table using a stored procedure.&nbsp;&nbsp;The criteria for what names to retrieve will be passed from a button the user will click.&nbsp;&nbsp;The recordset of names will then be placed in a select object using a loop.&nbsp;&nbsp;<br><br>I would like to be able to call the function each time the user selects a button and the select object will refresh with a list of names. <br><br>1)Can this be achieved on one page and is so how? <br><br>2)Or is there a way to do this without having to make multiple trips to the server (returning the entire unfiltered recordset of names and then sorting them after a user clicks a button and refreshing the select object)?
 
Dear c2Compliant,<br><br>1) Use a hidden form variable to pass the SQL filter value to the server code. Then use it in your stored procedure and build the &lt;select&gt;&lt;option&gt;.... tags from the resultant rows.<br><br>&lt;%<br>&nbsp;&nbsp;var category = &quot;1&quot;; // default value<br>&nbsp;&nbsp;if ( !isNaN(Request(&quot;CATID&quot;)) )<br>&nbsp;&nbsp;&nbsp;&nbsp;category = new String(Request(&quot;CATID&quot;));<br><br>&nbsp;&nbsp;... create a ADODB.Recordset and connection objects or whatever to call the stored proc sending it category filter<br><br>&nbsp;&nbsp;var sel = &quot;&lt;select name='validnames'&gt;\r\n&quot;;<br>&nbsp;&nbsp;while ( !rs.EOF)<br>&nbsp;&nbsp;&nbsp;&nbsp;sel += &quot;&lt;option value='&quot; + rs(&quot;nameID&quot;) + &quot;'&gt;&quot; + rs(&quot;name&quot;) + &quot;&lt;/option&gt;\r\n&quot;;<br><br>&nbsp;&nbsp;sel += &quot;&lt;/select&gt;\r\n&quot;;<br>%&gt;<br>&lt;form name=&quot;form1&quot; ....&gt;<br>&lt;input type=hidden name=&quot;CATID&quot; value=&quot;&lt;%=category%&gt;&quot;&gt;<br>&lt;input type=button value=&quot;Cat One&quot; onclick=&quot;document.form1.CATID.value = 1; document.form1.submit();&quot;&gt;<br>&lt;input type=button value=&quot;Cat Two&quot; onclick=&quot;document.form1.CATID.value = 2; document.form1.submit();&quot;&gt;<br>&lt;%=sel%&gt;<br>&lt;/form&gt;<br><br>2) Yes you can send all the data to the client if you like as well. There are several designs you could use.<br><br>You can generate separate &lt;select&gt; tags for each category and place each one in it's own &lt;div&gt; tag and control their visibility using CSS and DHTML. If you only have to support IE this is very simple. With Nutscrap it get's a little more difficult but you might get it to work.<br><br>Or... you could build script arrays for each category and dynamically change the contents of the &lt;select&gt; tag using DHTML.<br><br>Still more but that's all I will do for now...<br><br>Hope this helps<br>-pete
 
The first solution appears to be what I'm looking for and I'm excited get it working. However, I'm a beginner and do not understand all of the code.<br><br><br>&nbsp;&nbsp;var category = &quot;1&quot;; // default value<br>&nbsp;&nbsp;if ( !isNaN(Request(&quot;CATID&quot;)) )<br>&nbsp;&nbsp;&nbsp;&nbsp;category = new String(Request(&quot;CATID&quot;));<br><br>&nbsp;&nbsp;var sel = &quot;&lt;select name='validnames'&gt;\r\n&quot;;<br><br>Questions:<br>1) &quot;var&quot; does that mean I should declare a variable for both category and sel or is this a function?<br>2) &quot;!isNaN&quot; is this a function that does something with the category id?<br>3) &quot;new string&quot; is this a function (it is highlighted blue in Interdev)?<br>4) Do I not need to use a &quot;then&quot; and &quot;end if&quot;?<br><br><br><br>Thank you<br>
 
Dear c2compliant,<br><br>I apologize for the confusion. My sample code is written in Javascript. I don't use VBScript much.<br><br>The variable named 'category' is used to store the value of the 'request' variable named 'CATID' which comes from the HTML form element of the same name. The isNaN() code is merely setting a default value of '1' for the CATID since the first time someone visits the page the request variable will not exist. In VB it would look something like this:<br><br>category = Request(&quot;CATID&quot;)<br>if strlen(category) &lt; 1 then<br>&nbsp;&nbsp;category = &quot;1&quot;<br>end if<br><br>Then you would use the 'category' variable to pass the value to your stored procedure that returns your filtered rowset based on the category ID.<br><br>The variable named 'sel' is short for 'select' and will be built to contain the complete html for a &lt;select&gt; tag and all it's enclosed &lt;option&gt; tags. So the VBScript code must perform string concatination, it would look something like this:<br><br>sel = &quot;&lt;select name='validnames'&gt;&quot;<br>while NOT rs.EOF then<br>&nbsp;&nbsp;sel = sel & &quot;&lt;option value='&quot; & rs(&quot;nameID&quot;) & &quot;'&gt;&quot; & rs(&quot;name&quot;) & &quot;&lt;/option&gt;&quot;<br>loop<br><br>There may be some syntax errors in my VBScript code.<br><br>Hope this helps<br>-pete
 
You can first use javascript to create arrays form the sql server <br><br>then onChange function of the select field you can then create a function to reload the select values<br><br>i live demo of that is <br><A HREF=" TARGET="_new"> do not remember the exact link to it but i know is is the <br>it was used when i created the page about a year back<br><br>it is the current projects page and at the bottom of the page there are a few dorp downlists where i have used some thing like this<br> <p>Unicorn11<br><a href=mailto:webmaster@tripmedia.com>webmaster@tripmedia.com</a><br><a href= > </a><br>Hi there it all likeminded fellows!!!!!!
 
I was able to successfully fill the select object from the server. However, now I would like to be able to pass the value of the the selection made from the user from within the select object.&nbsp;&nbsp;The error I get is &quot;object required&quot; when I try to use client side scripting such as the following:<br><br>&lt;SCRIPT LANGUAGE=VBS&gt;<br>SUB BUTTON1_ONCLICK()<br>msgbox validatenames.value<br>END SUB<br>&lt;/SCRIPT&gt;<br><br>Any suggestions? <br>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top