Form submission problem

B

Bill S.

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
 
M

Mikhail Esteves

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:
 
T

Tom B

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

%>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,054
Latest member
TrimKetoBoost

Latest Threads

Top