Wrox Programmer Forums
|
ASP Forms As of Oct 5, 2005, this forum is now locked. Please use "Classic ASP beginner" at http://p2p.wrox.com/forum.asp?FORUM_ID=54 or "Classic ASP Professional" http://p2p.wrox.com/forum.asp?FORUM_ID=56 instead.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the ASP Forms section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old March 23rd, 2004, 07:36 PM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default Client Side OnSubmit Form Validation

Hello,

I have a form that is runs within a proprietary application. The prop app allows you to use type=submit buttons to perform certain tasks, in addition to submit the form data. I currently have a VBScript running on the Form_OnSubmit event to validate the form data. However, because the other button types are of a type=submit, they also trigger my script. So, here's the question:

Does anyone know how I can determine which submit button was clicked? If I could, I could easily run the script, or not.

Thanks,

Chris

 
Old March 23rd, 2004, 08:15 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

You could use JavaScript.

<form>
<input type=submit onclick=form1_onsubmit(1)>
<input type=submit onclick=form1_onsubmit(2)>
</form>
<script language=javascript>
function form1_onsubmit(num)
{
 alert(num);
}
</script>

Something like that, then replace alert(num) with any other JavaScript you want to call.

HTH,

----------
---Snib---
----------

<><
 
Old March 23rd, 2004, 09:30 PM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

Snib,

Thanks, for the input. However, it doesn't quite do the trick. I'm using VBScript, as I'm more familiar with VBS, than JS. But, it should work the same. This is what I did:

<SCRIPT Language=VBScript>
Function OBForm_OnSubmit(btnNum)

If btnNum = 1 Then
     'Run validation script.
End if

End Function
</SCRIPT>

<input type="submit" value="Save Data" name="OBBtn_Save" onclick=obform_onSubmit(1)>
<input type="submit" value="View Related Documents" name="OBBtn_CrossReference" onclick=obform_onSubmit(2)>


However, it would act as expected at first. Then, it would still trigger the OnSubmit event for the form, without an argument and would give a Type Mismatch '[string]: "[object]"]' error.

Here is what I finally found to work (again, using VBScript):
<SCRIPT Language=VBScript>
Function OBForm_OnSubmit()
    'This is not really needed any more.
End Function

Function OBBtn_Save_OnClick()
    'Validation code here that returns a true/false.
End Function
</SCRIPT>
<FORM Name=OBForm>
<input type="submit" value="Save Data" name="OBBtn_Save">
<input type="submit" value="View Related Documents" name="OBBtn_CrossReference">
</FORM>
It turned out to be far simpler than I thought. Thanks, again.

Chris
 
Old March 24th, 2004, 12:10 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

Be aware that using VBScript as your client-side language greatly restricts the client capabilities. Only IE clients will be able to run that code. If you are going to be doing any kind of client side scripting, it's highly recommended that you learn javascript.
 
Old March 26th, 2004, 10:39 AM
Registered User
 
Join Date: Mar 2004
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
Default

planoie,

Thanks for the reply. I am aware of the limitation. Fortunately, this application is running in a corporate environment where IE is the standard. Additionally, 99% of the time these forms will be displayed will be within an IE control embedded into a proprietary application.

Regards,

Chris






Similar Threads
Thread Thread Starter Forum Replies Last Post
Client Side Validation anujrathi ASP.NET 1.0 and 1.1 Professional 1 June 17th, 2006 10:23 PM
checkbox validation on client side using Javascrip sansircar ASP.NET 1.0 and 1.1 Professional 0 October 17th, 2005 07:43 PM
Posting form After Custom Client-side validation rathbird General .NET 3 March 4th, 2004 06:03 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.