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!

passing a parameter

Status
Not open for further replies.

Seeff

Programmer
Dec 2, 2002
33
IL
I have the following code on my page:

Agent number: <%=AGENT%> </b></u>     Select an agent:
<select name=&quot;AGENT&quot; onchange=&quot;OnAgentChange()&quot;>
<option value=&quot;(none)&quot;>
<%AgentsNum.MoveFirst
do while Not AgentsNum.EOF%>
<option value=&quot;<%=AgentsNum.Fields(0)%>&quot;><%=AgentsNum.Fields(0)%>
<%AgentsNum.MoveNext
loop%>

AND ALSO
<form method=&quot;get&quot; name=&quot;MapForm&quot;>
<input type=&quot;hidden&quot; name=&quot;AGENT&quot; value=&quot;<%=Request(&quot;AGENT&quot;)%>&quot;>

When my page refreshes as a result of a certain function, I would like to retain the AGENT value selected from the combo box. I suspect it becomes &quot;(none)&quot; because of the <option value=&quot;(none)&quot;>

How do I do this? Many thanks in advance to all the responders!
 
Just refreshing the page doesnt send the form data to the server, it only reloads the URL in the browser.
If you want the form data to be sent to the server you need to submit the form, either with a button click or a line of script in the html page.

If you want the combo to keep the selected agent, for each record in AgentsNum check if AgentsNum.Fields(0)=Request(&quot;AGENT&quot;). If so, add
Code:
selected
to the option tag.
 
Agent number: <%=AGENT%> </b></u> Select an agent:

<select name=&quot;AGENT&quot; onchange=&quot;OnAgentChange()&quot;>
<option value=&quot;(none)&quot;>

<%
AgentsNum.MoveFirst
do while Not AgentsNum.EOF
IF request(&quot;agent&quot;) = agentsNum(0) then keyword = &quot;SELECTED&quot; else keyword=&quot;&quot;
response.write &quot;<option value='&quot; & AgentsNum(0) & &quot;' &quot; & keyWord& &quot;>&quot; & AgentsNum(0)
AgentsNum.MoveNext
loop
%>
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Thanks Mike....I still have a problem with the fact that the value of AGENT has a comma before the number i.e. &quot;,4&quot;. AGENT also tends to grow: ,1,6,12 etc each time I select a new value from the combo.

I have an SQL further on in the code that makes use of AGENT. It does not work with a comma. Any ideas?

 
Are you sure that there is a comma before the start of the string?


<%
agentString = mid(request(&quot;agent&quot;),2) 'cuts off first comma
agentArr = split(agentString,&quot;,&quot;) 'puts each number into an array

if not isArray(agentArr) then agentArr(0) = 0
htmlString = &quot;<option value=''>Select One&quot;
AgentsNum.MoveFirst
do while Not AgentsNum.EOF
IF agentArr(0) = agentsNum(0) then keyword = &quot;SELECTED&quot; else keyword=&quot;&quot;
htmlString = htmlString & &quot;<option value='&quot; & AgentsNum(0) & &quot;' &quot; & keyWord& &quot;>&quot; & AgentsNum(0)
AgentsNum.MoveNext
loop
%>

<select><%=htmlString%></select>



As for your sql - you'll have to loop through the array...

for x = 0 to uBound(agentArr)
strSQL = &quot;INSERT INTO myTable (agent) VALUES (&quot;& agentArr(x) &&quot;)&quot;
objConn.execute(strSQL)
next Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Seeff, that the value of AGENT grows each time you select an agent implies that you store the Request(&quot;AGENT&quot;) in a form field also named AGENT. A hidden field maybe?
 
Gny...you are right....there is a:

<input type=&quot;hidden&quot; name=&quot;AGENT&quot; value=&quot;<%=Request(&quot;AGENT&quot;)%>&quot;>

How do I change this? What should it be in order that I can request the AGENT value?

Thanks
 
Isn't it enough that you have the AGENT value in the combo box?
 
I thought it should be enough, but I have an SQL further on in the code that does not have a value for AGENT. Maybe my SQL statement is wrong?

Dim strConn
Dim oRs
Dim strDataFile1

strDataFile1 = Server.MapPath(&quot;/main.mdb&quot;)

Set oRs = CreateObject(&quot;ADODB.Recordset&quot;)
strConn = &quot;Provider=Microsoft.Jet.OLEDB.4.0;Data Source=&quot; & strDataFile1
oRs.CursorLocation = 3 ' adUseClient
oRs.Open &quot;SELECT * from main where agent_new=&quot;& AGENT, strConn, , ,1
 
what value is agent. integer or string?

should be more so to this if string
s.Open &quot;SELECT * from main where agent_new='&quot;& AGENT & &quot;'&quot;, strConn
numeric
s.Open &quot;SELECT * from main where agent_new=&quot;& AGENT & &quot;&quot;, strConn _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
Shouldn't
SELECT * from main where agent_new=&quot;& AGENT
be
SELECT * from main where agent_new=&quot;& Request(&quot;AGENT&quot;)
?
 
Both don't work. That is the reason I thought I should have a hidden field with a parameter passed.

Lets say a new field with a parameter is a solution, how should the field syntax be? As above?
 
Well, you can only use Request(&quot;AGENT&quot;) in that query if Request(&quot;AGENT&quot;) holds a value. If not, you will get an SQL syntax error.
 
I think maybe the Update might be wrong and thus the parameter not being passed. It looks like this:

function updateMap() {
MapForm.Cmd.value='none';
MapForm.min.value='';
MapForm.max.value='';
MapForm.AGENT.value=agent;
MapForm.submit();
}
 
<%

thisAgent = request(&quot;agent&quot;)
if thisAgent = &quot;&quot; then thisAgent = 0

set agentsNum = objCN.execute(&quot;SELECT agentNum FROM myTbl&quot;)
htmlString = &quot;<option value=''>Select One&quot;
'AgentsNum.MoveFirst
do while Not AgentsNum.EOF
IF thisAgent = agentsNum(0) then keyword = &quot;SELECTED&quot; else keyword=&quot;&quot;
htmlString = htmlString & &quot;<option value='&quot; & AgentsNum(0) & &quot;' &quot; & keyWord& &quot;>&quot; & AgentsNum(0)
AgentsNum.MoveNext
loop
%>

<select><%=htmlString%></select>

<%
oRs.Open &quot;SELECT * from main where agent_new=&quot;& thisAgent, strConn, , ,1
%>
Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
MapForm.AGENT.value=agent; you are telling the script ot give the form field the value of a variable. I don't see agent anywhere in any declarations so I'm assuming it is a sting value that needs to be surounded with &quot; &quot;
MapForm.AGENT.value=&quot;agent&quot;;


It sounds like you have quite a few bugs floating around here. perhaps stepping back and starting some workflow and debuging steps are really whats going to help you the most.
sometimes flowcharting your workflow really does help if you have not or never do. remember those square and triangle chart thingies. [smile]
write all your values that are being declared and thus are passed to other objects to the screen and when they are client side alert them all so you are certain you're passing values and or (server side declarations) have the correct values in things such as your SQL statments and such.

It looks like we're going to be going back and forth for quite awhile here looking for a bug that may be more wide spread then it may appear to be. _______________________________________________
{ str = &quot;sleep is good for you. sleep gives you the energy you need to function&quot;;
ptr = /sleep/gi;Nstr = str.replace(ptr,&quot;coffee&quot;);alert(Nstr); }

_______________________________________________
for the best results to your questions: FAQ333-2924
has you're questio
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top