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 derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

2 Forms and One page

Status
Not open for further replies.

qberta01

Programmer
Joined
Nov 14, 2005
Messages
113
Hello...before I start posting lengthy code I thought I would ask if what I want to accomplish is even possible. Or maybe someone can suggest an easier route...even if it involves several ASP pages...I figure resolution may involve Javascript which is why I am posting here.....

I am working with classic ASP.I have a form in the page that presents a text box where the user will type in a value to be searched, i.e. a customer Name. Once the submit button it clicked some server-side code is executed to retrieve the customer data and I have another form in that same page that displays the searched for data (i.e. Customer's name and Status) with another submit button allowing for further action i.e. change customer status to inactive. When the submit button is clicked the database is once again updated. However, I would like the updated customer data to be visible to the user. Currently, it just shows the search text box and it's submit buttons....

Any help is greatly appreciated!

-Q



 
I don't know ASP, and this is definitely the wrong forum for your question, but I'll describe the process to you as well as I can understand your needs.

Also, I often have a question that is revelant to two or three different forums here. There should be a general Web dev forum, but I guess there's not.

A page with two forms is no problem at all...
Code:
<html>
<body>
<form id="form1" action="thispage.asp" method="post">
    <input type="text" name="fm1fld1" id="fm1fld1" />
    <input type="submit" />
</form>

<form id="form2" action="thispage.asp" method="post">
    <input type="text" name="fm2fld1" id="fm2fld1" />
    <input type="submit" />
</form>

That's all, but that's the easy part.

Okay. These two forms need to go into a page that processes itself. The example shows the page to be "[tt]thispage.asp[/tt]".

Have it read the values submitted then use a conditional statement to determine what to do with it. If the value from the first form was submitted, run your server-side code, maybe a databse query, and stick the results in the second form field.

So, referring to my earlier example, your code should say something like this pseudo-code:

Code:
    if ( defined $cgi->param('fm1fld1') ) {
        $results = run_query( $cgi->param('fm1fld1') );
        show_form( $results );
    } else if ( defined $cgi->param('fm2fld1') ) {
        $results = update_cust( $cgi->param('fm2fld2') );
        if ( $results == "success" ) {
            success();
        } else {
            failure();
        }
    } else {
        show_form();
    }

Now. The JavaScript equavalent of what you need to do when the first form is processed is something like
Code:
document.getElementById('fm2fld1').value = '<some value>';
, but I suspect that you won't have to resort to JavaScript. Just set the [tt]value=[/tt] property of the field when you generate the form.

--
-- Ghodmode
 
The "general Web dev forum" is either the Web Site Designer forum

forum253

or the HTML, XHTML & CSS (Cascading Style Sheets) Forum

forum215

As Ghodmode pointed out, this isn't really a Javascript question, but not an ASP question, either. It would be best addressed in the HTML forum listed above.

That said, you can have more than one form on the page, submit to different pages with the same form, or submit different information to the same page with different forms on the same page.

To create a page like you described, you'd check to see what, if any, form variables were submitted when the page loads, then display or not display areas of the form (you only need one) that are relevant to the data requested.

Lee
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top