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

ASP with JavaScript

Status
Not open for further replies.

QueenP

Programmer
Oct 22, 2002
16
BR
I asked almost the same thing a while ago but I wasn't clear and everything has changed now.

I have this search page in whicn you can search by code, part of the name, or city of the client.

When you search by code everything is fine, it just returns one client. The problem is when you search by anything else, it can return more than one client.

If this happens, you must choose on of the clients shown on screen.

The problem I'm having is that I need the client code and when I search by city or name part I always get the code from the last client in the record.

Is there a way to pass the code from the client I've selected to a JavaScript? Or at least to save the right code in a Session??

Thanks
 
It sounds like you have just 2 pages at the moment - one form to enter the search and another to give the details of the selected client?

You would be better of having 3 pages - one to search, the second to return a summary of each client matching the criteria (maybe just the name/code) and then the third to display all the details of that client.

In addition, you could put a check on page 2 that if the search only returns one record, it automatically redirects to the third page. --James
 
You're right, I have 2 pages right now. I make the search on the first one, then if there's only one result returned, it goes back to the first page with the result, if there's more than one client returned, it shows all the clients.

It shows the basic information and then a button which I click and it has to send the information back to the first page.

The problem I have is just that I can't retrieve the client code to a Session. It passes the code to a java script, but then I'd need to put the specific code into a Session and it just doesn't work.
 
I'm not exactly sure what you are trying to do but it shouldn't be too hard to get the result you want.

I'm assuming what you need to do is just send a single client code to the first page and then it will display the results? If so, on your second page you could use hidden form fields if you need to POST the info back. Just loop through the recordset and for each one you have a line something like:

Code:
<form action=&quot;page1.asp&quot; method=&quot;post&quot;>
<%= rs(&quot;clientname&quot;) %>
<input type=&quot;hidden&quot; value=&quot;<%= rs(&quot;clientcode&quot;) %>&quot;>
<input type=&quot;submit&quot; value=&quot;Select&quot;>
</form>

If page 1 gets the code from the querystring you could use a line like this for each record:

Code:
<a href=&quot;page1.asp?code=<%= rs(&quot;clientcode&quot;) %>&quot;><%= rs(&quot;clientname&quot;) %></a>
--James
 
thisPage.asp

<%
clCode = request(&quot;clCode&quot;)
clName = request(&quot;clName&quot;)
clCity = request(&quot;clCity&quot;)
strHTML = &quot;Please Enter Search Criteria&quot;

IF clCode <> &quot;&quot; or clName <> &quot;&quot; or clCity <> &quot;&quot; THEN
strHTML = &quot;No Data Found - Please select new criteria&quot;
strSQL = &quot;SELECT * FROM myTable WHERE 1=1&quot;
IF clCode <> &quot;&quot; Then strSQL = strSQL & &quot; AND clCode = &quot; & clCode
IF clName <> &quot;&quot; Then strSQL = strSQL & &quot; AND clName Like '%&quot; & clName & &quot;%'&quot;
IF clCity <> &quot;&quot; Then strSQL = strSQL & &quot; AND clCity Like '%&quot; & clCity & &quot;%'&quot;
set objRS = objCN.execute(strSQL)
IF NOT objRS.EOF THEN
arrData = objRS.getRows
numRecords = uBound(arrData,2) + 1
If numRecords = 1 THEN
strHTML = &quot;write you detail string here&quot;
elseif numRecords > 1 THEN
strHTML = &quot;Click on Name to see detail&quot;
for i = 0 to numRecords - 1
strHTML = strHTML &_
&quot;<br><a href='thisPage.asp?clCode='&quot;& arrData(0,i) & &quot;'>&quot;&arrData(1,i)&&quot;</a>&quot;
next
end if
end if
END IF
%>

<form action=&quot;thisPage.asp&quot; method=&quot;post&quot;>
<input name=&quot;clCode&quot;>
<input name=&quot;clName&quot;>
<input name=&quot;clCity&quot;>
<input type=submit>
</form>
<br>
<%=strHTML%> Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Thanks for the help.

I'll try them and see if it works here.
 
Oops! I forgot to post my explanation - and I found a typo.

This is a one page solution. If no data has been posted to the page yet the message is &quot;please enter search criteria&quot;. If only one record is returned based on the criteria, you display that record. If multiple records are found, you display a list the calls the page again when one of the names is clicked (thus showing the detail for that record).

Typo in this line (misplaced single quote):
&quot;<br><a href='thisPage.asp?clCode='&quot;& arrData(0,i) & &quot;'>&quot;&arrData(1,i)&&quot;</a>&quot;

Should read:
&quot;<br><a href='thisPage.asp?clCode=&quot; & arrData(0,i) & &quot;'>&quot; & arrData(1,i) & &quot;</a>&quot;

Get the Best Answers! faq333-2924
&quot;A witty saying proves nothing.&quot; - Voltaire
mikewolf@tst-us.com
 
Thanks mwolf00, but I really need two pages.

It's an application made to save the helpdesk calls made by the clients.

The thing is that I'm the fourth person to take a look at it, so I don't have much of an idea what the first person was thinking about when he wrote the code.

The code actually shows the client info on the first page using javascript and window.opener.form1.value on the second page.

I'm don't think I was too clear also. Everything is working. If there's more than one client, it stores in a array, and then the number has to be passed, so the Session(&quot;code&quot;) = arCode(num) but I cannot get this num right because when you click the button it goes to a javascript and I don't know how to send this value to a Session.
 
You can't get the value into a Session variable without sending it to another ASP page. Why are you using a Session variable? If it is just to send the selected code to the details page then using a form or the querystring would be MUCH easier.

To be honest, from what I can gather, it sounds like this whole system could do with a slight rethink. It seems to be using over-complicated methods of achieving quite a simple result? --James
 
The Session variable is because I use the code in this timer.asp -- when it reaches 5 minutes, it shows a message with the code of the client, which get from the Session.

I just had an idea to get this value with a querystring, I just don't know how to send it from the second page to the timer.asp page.
 
thisPage.asp

<%
clCode = request(&quot;clCode&quot;)
clName = request(&quot;clName&quot;)
clCity = request(&quot;clCity&quot;)
strHTML = &quot;Please Enter Search Criteria&quot;

IF clCode <> &quot;&quot; or clName <> &quot;&quot; or clCity <> &quot;&quot; THEN
strHTML = &quot;No Data Found - Please select new criteria&quot;
strSQL = &quot;SELECT * FROM myTable WHERE 1=1&quot;
IF clCode <> &quot;&quot; Then strSQL = strSQL & &quot; AND clCode = &quot; & clCode
IF clName <> &quot;&quot; Then strSQL = strSQL & &quot; AND clName Like '%&quot; & clName & &quot;%'&quot;
IF clCity <> &quot;&quot; Then strSQL = strSQL & &quot; AND clCity Like '%&quot; & clCity & &quot;%'&quot;
set objRS = objCN.execute(strSQL)
IF NOT objRS.EOF THEN
arrData = objRS.getRows
numRecords = uBound(arrData,2) + 1
If numRecords = 1 THEN
session(&quot;resultCode&quot;) = arrData(0,i)
response.redirect &quot;page2.asp?clCode=&quot; & arrData(0,i)

elseif numRecords > 1 THEN
strHTML = &quot;Click on Name to see detail&quot;
for i = 0 to numRecords - 1
strHTML = strHTML &_
&quot;<br><a href='thisPage.asp?clCode='&quot;& arrData(0,i) & &quot;'>&quot;&arrData(1,i)&&quot;</a>&quot;
next
end if
end if
END IF
%>

<form action=&quot;thisPage.asp&quot; method=&quot;post&quot;>
<input name=&quot;clCode&quot;>
<input name=&quot;clName&quot;>
<input name=&quot;clCity&quot;>
<input type=submit>
</form>
<br>
<%=strHTML%> Get the Best Answers! faq333-2924
Is this an asp FAQ? faq333-3048

mikewolf@tst-us.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top