469,306 Members | 1,850 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,306 developers. It's quick & easy.

Form submission problem

Hi,

I am just starting to work with ASP, so bear that in mind...

I have an ASP page that displays records from a table, and
allows you to add, update and delete. There is a form with
one button that does adds and updates, and a second button
for deletes.

What I want to do is, instead of having the 'action' of the
form be something like:

action="updateUser.asp?mode=update"

I want to use the onClick property of Add/Update and Delete
buttons to set a value in a hidden field in the table, and NOT
have a query string, ie: action="updateUser.asp"

The problem is that I have an 'If' statement to determine if
I need to do an add/update/delete or just display the records
and form:

If (Request.Form("txtAction") = "update" Or
Request.Form("txtAction") = "delete") Then

do some stuff...

End If

The problem is that when it runs, and the page is first
displayed, I get:

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dms/updateUser.asp, line 49, column 43
If (Request.Form("txtAction") = "update" Or
------------------------------------------^
This makes sense if you can't include a form field in
an If statement before the form has even been defined.
So I put an If statement before it to determine that case:

If Request.Form.Count > 0 Then
Is there a better way to do this? Is there something
obviously wrong with the If statement?

tia,
Bill
Jul 19 '05 #1
2 3311
This is one way of changing the form action using javascript:

<script language="JavaScript">
// Changes the form txtAction variable and submits the form
function chgAction(m_action){
document.formname.txtAction = m_action;
document.formname.submit();
}
</script>

<form name="formname" action="updateUser.asp">
<input type="hidden" name="txtAction" value="">

blah-blah

<input type="button" value="Add"
onClick="javascript:chgAction('add');">
<input type="button" value="Update"
onClick="javascript:chgAction('update');">
</form>

As for your ASP syntax error, try putting that whole thing in one line
without breaking them up into two.
Bill S., on Wed, 05 Nov 2003 15:43:41 -0800, had to say:
Hi,

I am just starting to work with ASP, so bear that in mind...

I have an ASP page that displays records from a table, and
allows you to add, update and delete. There is a form with
one button that does adds and updates, and a second button
for deletes.

What I want to do is, instead of having the 'action' of the
form be something like:

action="updateUser.asp?mode=update"

I want to use the onClick property of Add/Update and Delete
buttons to set a value in a hidden field in the table, and NOT
have a query string, ie: action="updateUser.asp"

The problem is that I have an 'If' statement to determine if
I need to do an add/update/delete or just display the records
and form:

If (Request.Form("txtAction") = "update" Or
Request.Form("txtAction") = "delete") Then

do some stuff...

End If

The problem is that when it runs, and the page is first
displayed, I get:

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dms/updateUser.asp, line 49, column 43
If (Request.Form("txtAction") = "update" Or
------------------------------------------^
This makes sense if you can't include a form field in
an If statement before the form has even been defined.
So I put an If statement before it to determine that case:

If Request.Form.Count > 0 Then
Is there a better way to do this? Is there something
obviously wrong with the If statement?

tia,
Bill


Jul 19 '05 #2
How about naming your two buttons the same?

<input type=Submit name=SubmitButton value="Update">
<input type=Submit name=SubmitButton value="Delete">

Then in your code....

<%
if Request.Form("SubmitButton")="Update" then
'Update
else
'probably Delete
end if

%>
"Bill S." <bi*********@hotmail.com> wrote in message
news:74**************************@posting.google.c om...
Hi,

I am just starting to work with ASP, so bear that in mind...

I have an ASP page that displays records from a table, and
allows you to add, update and delete. There is a form with
one button that does adds and updates, and a second button
for deletes.

What I want to do is, instead of having the 'action' of the
form be something like:

action="updateUser.asp?mode=update"

I want to use the onClick property of Add/Update and Delete
buttons to set a value in a hidden field in the table, and NOT
have a query string, ie: action="updateUser.asp"

The problem is that I have an 'If' statement to determine if
I need to do an add/update/delete or just display the records
and form:

If (Request.Form("txtAction") = "update" Or
Request.Form("txtAction") = "delete") Then

do some stuff...

End If

The problem is that when it runs, and the page is first
displayed, I get:

Error Type:
Microsoft VBScript compilation (0x800A03EA)
Syntax error
/dms/updateUser.asp, line 49, column 43
If (Request.Form("txtAction") = "update" Or
------------------------------------------^
This makes sense if you can't include a form field in
an If statement before the form has even been defined.
So I put an If statement before it to determine that case:

If Request.Form.Count > 0 Then
Is there a better way to do this? Is there something
obviously wrong with the If statement?

tia,
Bill

Jul 19 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.

By using this site, you agree to our Privacy Policy and Terms of Use.