Forums

This topic is locked

Use a function for a form action

Posted 13 Sep 2006 21:51:12
1
has voted
13 Sep 2006 21:51:12 Jerry S Graham posted:
I want to have multiple actions for a form bases on which button is selected by th3e user - Insert Record, Delete Record, Select Record or Update Record. I have seen an exacple somewhere about how to use a fuction call in the form action but I can't find it again. Is there a simple way to have one of a number of actions based on a function call with a case statement or series of ifs?

Something like: <form name="AddIncident" id="AddIncident" method="POST" action="<%=SelectAction()%>">

SelectAction() would select one of the above mentioned actions.

By way of explaination: I am trying to trap my users in a loop here where they enter multiple incidents for a specific event. They may need to scroll forward or backward through the incidents before they have completed the process - thus the need for multiple possible actions on the form.

I am using ASP and VBScript.

Replies

Replied 26 Sep 2006 03:48:50
26 Sep 2006 03:48:50 Jerry S Graham replied:
I'm not sure if my question was ambiguous or not but it deserves an answer because I am sure I am not the first (or last) poor soul who wants to do this. So, for any who care and for the record - I answered it myself.

It finally dawned on me that if you can write the html code for a form than you must be able to reference the properties through scripting code also. So this code below will allow me to do just about whatever I want when the user pushes one of my buttons. Soooo... here is the simplified code. It will work just as it is, but obviously you want to do more than this with it.

<html>
<head>
<script type="text/vbscript">
Dim selVal

function SetVal(selVal)
document.form1.Clicked.value = selVal
document.form1.method = "Post"
select case selVal
case "Add"
document.form1.action = "Add.asp"
case "Delete"
document.form1.action = "Delete.asp"
case "Next"
document.form1.action = "Next.asp"
case "Previous"
document.form1.action = "Previous.asp"
case "Nothing"
document.form1.method = ""
document.form1.Clicked.value = "I am now on strike!"
exit function
end select
document.form1.submit()
End function
</script>
<title>Change Action Test</title>
</head>
<body>
<form name="form1" id="form1">
<input name="Clicked" type="text" value="" />
<br>
<input name="Add" type="button" value="Add" onclick="SetVal('Add')" />
<input name="Previous" type="button" value="Previous" onclick="SetVal('Previous')" />
<input name="Next" type="button" value="Next" onclick="SetVal('Next')" />
<input name="Delete" type="button" value="Delete" onclick="SetVal('Delete')" />
<input name="Nothing" type="button" value="Nothing" onclick="SetVal('Nothing')" />
</form>
</body>
</html>

I substituted the "Add.asp" action with the following code in my 'real' page, which also contains all the asp code behind the action. I didn't include all that here or you would never get through this post.

case "Add"
document.AddIncident.action = "<%=MM_editAction%>"

Also, if you want to test this yourself you will have to create the above links as separate pages or you will get a 'page cannot be found' error.

Now my problem is to do multiple optional recordset actions within the same page depending on which action the user chooses to take. I suppose I will have to answer that question myself also but I will certainly post the answer here so others can benefit from it.

This link at Microsoft was a bit of a help:
msdn.microsoft.com/library/default.asp?url=/workshop/author/forms/formsoverview.asp

Reply to this topic