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 January 15th, 2004, 06:23 AM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 141
Thanks: 0
Thanked 0 Times in 0 Posts
Send a message via MSN to acdsky
Default Auto Populate Form

Hi

I have got a form with a bunch of list boxes and text boxes. What I would like to do is to populate certian fields and/or make certian selections available depending on what was selected on a list box.

My question is, how do you trigger some code uppon some kind of event? For example in VB6 you would have a upon selection event for a listbox, I would like to achieve this with ASP/VBS.

Regards
Marnus

Such is Life!
 
Old January 15th, 2004, 10:44 AM
planoie's Avatar
Friend of Wrox
 
Join Date: Aug 2003
Posts: 5,407
Thanks: 0
Thanked 16 Times in 16 Posts
Default

First you must make the form submit to the page it's on:

<form action="<%=Request.ServerVariables("SCRIPT_NAME")% >">


I'd recommend creating a javascript function to handle the form's events and utilizing a hidden form field to save which event was fired:

<input type="hidden" name="hidFormEvent">
<script language="javascript">
function doPostBack(sEvent, objForm){
    objForm.hidFormEvent.value = sEvent;
    objForm.submit();
}
</script>


In the list box, you can force the form to submit with some javascript:

<select name="lstMyChoices" size="10" onChange="doPostBack('lstMyChoices_Changed',this.f orm);">


Then can write the form processing code on this page to accomodate what happens on the post back submit. Presumably you will have some button on the page as well as the list box, so you can add that into the post processing logic.

<input type="submit" name="cmdSaveStuff">

One of the nice things about submit buttons (and images) is that their value's aren't submitted unless they are actually clicked. So you can have 10 submit buttons on the page, they will all submit the form, but only the button that was clicked will appear in the Request.Form() collection. So this we can incorporate into the form processing code.

'First check for a form post
If Request.ServerVariables("CONTENT_LENGTH") > 0 Then
    'Pick event
    Select Case Request.Form("hidFormEvent")
        Case "lstMyChoices_Changed"
            'Do what you need when you change the list box selection
    End Select

    If Request.Form("cmdSaveStuff") <> "" Then
        'Put your save logic here.
    End If
End If


Peter
------------------------------------------------------
Work smarter, not harder.





Similar Threads
Thread Thread Starter Forum Replies Last Post
Auto populate/look up slim Access 6 May 31st, 2007 03:58 AM
GridView auto populate stonesbg ASP.NET 1.0 and 1.1 Basics 0 February 19th, 2007 10:41 AM
Auto-populate table data into form jeff394 Access VBA 2 April 19th, 2006 02:55 PM
Auto Populate fields in a form mnemec24 Access 8 March 9th, 2005 02:11 PM
Auto Populate a field ? mar0364 Classic ASP Databases 4 July 9th, 2004 11:10 AM





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