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!

how to call asp in client side vbscript? 3

Status
Not open for further replies.

Kingkumar

Programmer
Jan 21, 2003
167
US
Hi ,

It might be answered before but i couldnt find it in search so started a new thread.

The problem i have is i have a bunch of list boxes and when user clicks on submit button witha client side script(vbscript) i am checking whether user has mades any/what selection and if he has not selected anything a message pops up to select something other wise it should call the stored procedure and send the values as parameters.

now i am able to do it till the part where i pop up a message box when user doent select something but the problem i am facing now is how to call the function ( whihc is in one of the com objects ) in the client side vbscript to do the required update in the database.

Thanks.

-KingKumar
 
Unless all of your client browsers have this COM object.... and unless you are absolutely certain that you will not need to change / upgrade the COM object ...

You should instead put the COM object on the web server.

The page should submit to an ASP where the form fields are either pulled out of the querystring (GET) or from the request header (POST). Then the ASP will create the COM object and invoke its methods.

Use the OnSubmit property of your HTML form to trigger your client side input checking function.
 
To clarify, change this: The page should submit to an ASP where ...

To this: The HTML form should submit to an ASP where ...
 
i understand what you mean sheco but the question i had was that i saw one example in javascript where the user on submit was calling a javascript function whcih checked for some stuff and later in the function it checked for an

if... clause and in the if condition it had asp code as
<%
' something to be done here with object create in the top asp code (server side script)basically gettting recordset into an array

%>
' back to javascript.


i was wondering if i could do something similar using vbscript

please let me know if i am not clear as i can see it in mind and not sure how clear i am on paper:)

i am looking for this kind of page movement as i want to post back to the same asp page stating whether update was success or failure


Thanks
 
Do you mean that the server side script was used to create some client side script?

For example if the array of possible valid answers is dynamic, the ASP could use fetch these values from a database or COM object. Then the ASP would use Response.Write to dynamically write the code for the browser-side's function.


Like this:

<html>
<head>
<title>sample demo thing</title>
<script>
function IsOK(myValue)
{
[red]
var foo = <% Response.Write("bar") %>;
[/red]
if (myValue == foo)
{ return true; }
else
{ return false; }
}
</script>
</head>
<body>
<form action='whatever.asp' method='post' OnSubmit='IsOk(blah)'>

blahblahblahblahblahba;bjhabajdfsjsadf

</form>
</body>
<html>

Of course it could be much more complicated that that, I was just trying to make sure I understand what you are talking about.
 
yeah something like that.
I thought it would be easier and simple to submit the form to itself instead of sending to someother asp page and then bringin back to the same page.

I dont know whether i am thinking in the right direction or not
Please let me know
thanks.

 
To expand some on what's been said already, the server side script produces code that is sent to the client computer, and after the code is sent from the server, the server side code is no longer active, it no longer is "running" on the server. Client side scripting is only active on the client computer, which has no connection (generally speaking) with the server except to send information when a page submits (which closes that page) and make requests to receive page data. The connection is basically like a phone call where after every question from the client and answer from the server, the phone is disconnected until the next "call" is made.

This question is a common one here, probably answered a couple times a month.

Lee
 
Yes sending the form to itself is a fine option.

All you have to do is check to see if the form has already been submitted or not. The easiest way to do it is to give your submit button a name. It will work without a name, but the name allow you to check Request.Form or Request.QueryString for that value... if it is absent the form has not been submitted.

like this:
<%
If Len(Request.Form("btnSubmit")) > 0 Then
'the form was submitted...

'write code to process it here
End If
%>
<html>
<body>
<form action="nameOfThisPage.asp" method="post">
blah blh asdjfsjdf

<input type='submit] name="btnSubmit" Value='submit me!'>
</form>
</body>
</html>
 
To do what you want, you have to have the script on the page to process the information submitted, if the page has been submitted to itself, and the script to set up the page if it's not the recipient of a submission.

This isn't an unusual method, though not the most common way of processing data. I often use a page to process the submitted data that isn't sent to the client computer, then redirect from there to another page so refreshing the page won't resubmit the data.

Lee
 
Hi Sheco,

Just to give you the picture of what i am doing ...
i have three forms
1st form has a dropdown which on change submits that form using get method and the page is redisplayed based on the selection in this form

2nd form has another drop down and on changeevent this form is submitted using get method and the page is redisplayed.

3rd form has this submit button and submits the form using post method and the page is redisplayed with message if the update was successful then success message otherwise failure message.


so using ur logic above IS IT SAFE TO ASSUEM THAT if only the page is redisplayed becasue of submit button click in the third form then only the code in the first asp delimiters will work right??? otherwise it would be skiped.

Thanks for your help

--King
 
Just to make sure I understand.... the first two forms on your page are submitted by script writting into the change event of a dropdown selection but the third form is submitted by clicking a button?
 
yeah thats right .

Also i have one more question .
is there a way to pass the variable in client side script to server side script ??
Thanks
king
 
The easiest way might be to make a hidden HTML form element like this:

<input type='hidden' name='whatever' value=''>

Then you can set its value in the function triggered by your OnSubmit() event.
 
As to the question of the 3 form page:

Assuming that the user must have selected some value other than an empty string for the first 2 forms, you can set up the server side code to work with nested IF statements:

IF Len(Request("btnSubmit") > 0 THEN
'3rd form was submitted.
[ do something ]
ELSE
if Len(Request("SecondDropDown") > 0 then
'2nd form was submitted
[ do something ]
else
IF Len(Request("FirstDropDown") > 0 THEN
'1st form was submitted
[do something ]
ELSE
'Nothing was submitted, first visit to this page!
END IF
end if
END IF


Or some other structure depending on your needs.
 
THANKS sheco ,
also why did u asked about the third form being submitted by button??/
Lemme know thanks for your time and help
--King
 
Consider the most basic submit button:
<input type='submit'>

This is not very useful if you want to submit to yourself, because you can't use it to tell if the page was actually submitted.


But if give your button a name and value:
<input type='submit' name='btnSubmit' value='Submit'>

This button is much better because, if nothing else, you KNOW that the value of this button will be submitted along with your form.

Suppose your form has 3 text boxes. And suppose the user put not value in any of them but mashes the submit button anyway.

Well you can check Request("btnSubmit") and it will equal the value that you set for it. You couldn't do this if you didn't give your button a name. Using this you will know if the page has been submitted. This is important with pages that submit to themselves because you need to know in your ASP code whether you are rendering the page for the first time or processing the results of a submission.

 
use double quotes because singles quotes will not validate in xhtml
 
Let me try another way. Consider this form:

<form action="thisPage.asp"
<input type='text' name='v1'>
<br>
<input type='text' name='v2'>
<br>
<input type='text' name='v3'>
<br>
<input type='submit'>
</form>

If a page with this form is submitted to itself then you can't just test the lenght of some value to know whether or not any particular execution of the ASP is the first or second pass.

The reason is that if the user allows the text boxes to be empty then their length is zero... the same as it is on the time the page is loaded.

You could check the value of Len(Request.Form("Supercalifragilisticespialadoscous")) and it will be zero because Request("xxx") will return an empty string for whatever value you put in, even if there was no such element in the submitted form.

So by giving your button a name and value, you always know that you can check that name in the request and it will always be there if the form was submitted and always be zero if it was not.
 
actually its

<form action="thisPage.asp" method="post">
<input type="text" name="v1">
<br>
<input type="text" name="v2">
<br>
<input type="text" name="v3">
<br>
<input type="submit">
</form>

you just forgot the ">" in the form
 
oh, it was just for an example... but you are good at catching these things. I think you would make a good partner for extreme programming.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top