Click to See Complete Forum and Search --> : URGENT!!! Please help....
turfbult
Jan 9th, 2001, 05:18 AM
Hi,
I have a website with 3 main pages - COUNTRY,STATE,CITY and then a DETAILS page.
On the COUNTRY page you select a COUNTRY, click submit, it the opens up the STATE page where you choose a STATE,click submit, the CITY page opens, you choose a city, click submit and then the DETAILS page opens showing details about the COUNTRY/STATE/CITY combination chosen!!
Now, some COUNTRIES do not have STATES (or I dont have them on my DB). At this stage, even though there are no STATES for the COUNTRY chosen the STATE page still opens with "ALL" in the dropdown menu..... and then onto CITY etc etc.
I want to change this so that when a COUNTRY is chosen, I want to run a quick query on my STATE table to see whether that COUNTRY does indeed have STATES - if it doesn't I want to redirect directly to the CITY page!!
How do I do this?? How do I know what COUNTRY was chosen before going to the STATE page.
I have this code for the redirect..
<script language="javascript">
function redirectpage()
{
if(document.frmcountry.lstcountry.options[document.frmcountry.lstcountry.selectedIndex].value == 0)
{
document.frmcountry.action = "city.asp";
document.frmcountry.submit();
}
else
{
document.frmcountry.submit();
}
}
</script>
This does not do what I want. My ideal is to have something like....
after the COUNTRY is chosen and the submit button is clicked...
1.) select * from STATES where country = lstcountry
2.) if EOF then (ie. no STATES found for that COUNTRY)
document.frmcountry.action = "city.asp";
document.frmcountry.submit();
else
document.frmcountry.action = "state.asp";
document.frmcountry.submit();
end if
Can I have ASP code within Javascript, because I only know ASP and do not know how to do the "select statement" using Javascript.
Please!!!! Your help will be very much appreciated.
Thank you,
T
Yes, you can have vbscript inside java.
Just add
<SCRIPT LANGUAGE=vbscript>
****Do your VB here
</SCRIPT>
Since I only know vbscript, I would handle your situation like this:
Dim rs as ("ADODB.Recordset")
****read from the database to find states
If rs.EOF then (ie. no STATES found for that COUNTRY)
Response.Redirect "city.asp";
Else
Response.Redirect "state.asp";
End if
turfbult
Jan 9th, 2001, 09:13 AM
Please.......... anybody..........
Im desperate!!
turfbult
Jan 9th, 2001, 09:19 AM
Thanks Steve!!
My problem is.. how do I know which COUNTRY was chosen and also.... I have hidden input boxes which contain data which in turn is "pulled thru" to all other pages when SUBMIT is clicked - as far as I know redirect will not work - the page must be posted for the "hidden inputs" to be pulled thru!!??
I should maybe mention that my redirectpage function is only "accessed" after the submit button is clicked, I do this using something like...
<input type="button" onclick="redirectpage()" value="submit"
So, within redirectpage() I want to find out what COUNTRY was clicked, check whether I have STATES for this country and then redirect/post to either STATE or CITY.
T
To know which state is selected, I will assume that the menu containing the states names is mnuStates.
After you are redirected, just use Request.Form:
strStateSelected = Request.Form("mnuStates")
I would also handle your submit button by having it in a form:
<FORM ACTION="Country.asp" METHOD="POST" id="form2" name="form2">
That way any button on your page will basically redirect back to country, then within country, have something like:
If request.form("mnuCountry") <> "" <----means that a country was selected, so add logic within here to redirect:
If Request.Form("mnuStates") = "" then
Response.Redirect "city.asp";
Else
Response.Redirect "state.asp";
End if
end if
[Edited by bubba on 01-09-2001 at 10:53 AM]
turfbult
Jan 9th, 2001, 10:49 AM
Steve,
1.) My problem is that I want to know what COUNTRY was selected BEFORE going to another page.
2.) When I reach my details page I need to know which COUNTRY/STATE/CITY was selected in the previous 3 pages so that I can query the DB with the those details - thats why I need to POST the page and not simply response.redirect "whateverpage", because by using redirect my hidden inputs wont be "pulled thru" to the next page - I MUST POST the page - That, is how I understand it!!
3.) Let me explain what I need again.....
In the COUNTRY page
When a COUNTRY is selected from the dropdown and submit is clicked the redirectpage function (as explained in my first post) must be executed and within that function I need to find out what COUNTRY was selected, do a sql query on my STATES table to find out whether I have STATES for that COUNTRY and then something like this..
if NOT eof then (ie. I have states)
document.frmcountry.action = "state.asp";
document.frmcountry.submit();
else (ie.I do not have any STATES on my db for this COUNTRY)
document.frmcountry.action = "city.asp";
document.frmcountry.submit();
end if
So, BEFORE(!!) leaving the COUNTRY page I must find out
1.)What COUNTRY was selected
2.)whether I have STATES for that COUNTRY
3.)and then go to either CITY or STATES page.
I hope this makes a bit more sense.
Thanks for your help - I do appreciate it.
T
The code I posted does do (you just have to try it) what you are saying you need to do, except for the hidden inputs, see if using include works, I believe it should:
Say "country.asp" as the hidden inputs:
In "state.asp" put in this code: (again, this is vbscript)
<!--#include ="country.asp" -->
turfbult
Jan 9th, 2001, 12:04 PM
Ok, I'm gonna give it a bash!! After reading thru your code a 2nd and 3rd time, I think I understand it a bit better.
Thanks, I'll let you know.
T
turfbult
Jan 9th, 2001, 12:17 PM
Steve,
Just before I try this out (and sorry if I'm being stupid)... does this code
strStateSelected = Request.Form("mnuStates")
come in country.asp or state.asp.
The reason why I'm asking is that if it has to come in state.asp - it is not what I want as I want to do all queries etc BEFORE "leaving" country.asp.
Like I said - sorry if I'm being thick, but this is a difficult one for me!!
T
turfbult
Jan 9th, 2001, 12:44 PM
Ok,
I did this ..in country.asp
<FORM ACTION="Country.asp" METHOD="POST" id="form2" name="form2">
strCountrySelected = Request.Form("lstcountry")
response.write strCountrySelected
Now what happens is that after the country is selected and the submit button is clicked the variable strStateSelected contains the country selected (in this case USA) and this is what I want - I want to know what country is selected.
I then added this code in country.asp
if request.form("lstcountry") = "USA" then
response.redirect "state.asp"
else
response.redirect "city.asp"
end if
I just hardcoded USA and did some redirects, just to test.
As soon as I see this work I'll obviously do my sql query to see whether I have STATES in my db for the COUNTRY selected and then according to that redirect to either STATE or CITY.
I now get this error!!
Response object error 'ASP 0156 : 80004005'
Header Error
/country.asp, line 51
The HTTP headers are already written to the client browser. Any HTTP header modifications must be made before writing page content.
Any suggestions??
turfbult
Jan 9th, 2001, 01:27 PM
Steve,
I'm replying to myself the whole time. Forget about my previous posts - lets try something else...
I want to leave everything as it was ie. when you choose a COUNTRY and then click submit you go to STATE.ASP, but now I want to change STATE.ASP like this...
before the HTML tag is reached all my ASP code is done so...
by the time STATE.ASP is loaded (before the HTML tag is reached) I know what COUNTRY was selected - it was "posted" from COUNTRY.ASP when the submit was clicked, so I want to do my sql query HERE and then either redirect to CITY.ASP or else just carry on loading STATE.ASP, but ONCE AGAIN my problem is that if I do a simple response.redirect "city.asp", my hidden inputs are not pulled thru so in CITY.ASP I don't know what COUNTRY was selected!!! If, however I can somehow "POST/SUBMIT" the page the COUNTRY will be pulled thru to CITY.ASP.
Heck, I hope I'm making sense!!?? It is extremely difficult to explain via "email".
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.