PDA

Click to See Complete Forum and Search --> : Calling a javascript function from vbscript


turfbult
Jan 10th, 2001, 02:27 AM
Hello,

Is it possible to call a javascript function from within vbscript and if so, how do I do it??

I have something like this...

<%
some code in here and from here I want to call a javascript function called test
%>

<script language="javascript">

function test()
{
some code in here
}

</script>

T

Ianpbaker
Jan 10th, 2001, 02:45 AM
Hi turfbult

I see you have the asp tags, do you mean you want to call the function from within the asp, if so it can't be done as asp is done solely at the server and can't interface with the client-side javascript. Also you can't access javascript through client-side vbscript either. If you just want to call the function if something has happened in asp you could do the following


<%
If myvar = something Then
%>
<body onload="test();">
<%
Else
%>
<body>
<%
End If

this will call the test function once the page has loaded.

Hope this helps

Ian

turfbult
Jan 10th, 2001, 04:17 AM
Thanks Ian,

It helps me in the sense that I realize that I cannot do what I had in mind!!
Maybe you can help me in any case!?? I have posted many questions about this but nobody can help.

I have 4 pages - COUNTRY.ASP, STATE.ASP, CITY.ASP and DETAILS.ASP. The whole idea is that you must select
a Country,State,City and then seen details of the combination selected. So, when DETAILS.ASP is
loaded I must know what COUNTRY/STATE/CITY was selected in the previous 3 pages and I do this using
hidden input which gets "pulled thru" from each page. I have however now realized that I do not have
STATES on my DB for all the different COuntries, so what I did is just display "ALL" in the STATES page
dropdown menu and when you the click submit it opens the CITY page and from there the DETAILS page.

This is a waste of time, so what I want to do is, after the Country on the COUNTRY.ASP page is selected
do a search on my DB to see if I have any STATES on my DB for that COUNTRY. If not, go directly to the CITY or
DETAILS page (knowing what COUNTRY was selected!!!!), if YES, then proceed loading the STATES.ASP page
and listing all the STATES.

Everyone is telling me to use response.redirect, but then the hidden inputs are not pulled thru to
my details page so I dont know which COUNTRY was selected - as far as I understand, the page MUST be
POSTED/SUBMITTED for the hidden inputs to be pulled thru!!??

I'll be most grateful (and more "quiet") if you or anyone can help me.

Thanks,
Turfbult.

Ianpbaker
Jan 10th, 2001, 04:29 AM
There are several solutions to your problem that you could you could do.

If you wanted to continue using the hidden fields then once you have checked to see if their are any states and their isn't you can build the page with just the hidden fields and automatically submit the form.

eg.

<html>
<body onload="document.myform.submit();"
<form name="myform" action="City.asp" method="Post">
<input type="hidden" name="city" value="<% = cityvar%>">
</form>
</body>
</html>

as long as you asp handles that no state has been entered then it will work fine.

alterantively you could add searchpages that redirect to the show pages and run them using querystrings.

eg. the user selects a country, it get's submitted to search state, if their is a state redirect to the state page using something like state.asp?countrycode=1 and if their isn't a state re-direct to the city page city.asp?countrycode=1

Either way will work, but I think the second way is cleaner

Hope this helps

Ian

turfbult
Jan 10th, 2001, 05:22 AM
Ian,

Thanks for your help, but I think I am in way over my head.

Back to the books/drawing board for me.

Cheers,
T