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

Form Multiple Button Submit - Call ASP Page 1

Status
Not open for further replies.

RWF

Programmer
Apr 16, 2001
24
US
The intent is to call an ASP page to perform a series of actions.

I have tried numerous variations with no luck. The concept of submitting a form is clear to me, but calling a specific ASP to perform an action from within a form is not.

Perhaps I am using the wrong approach in this, and may in fact not even need a form, although that will become necessary in the future.

The following produces no errors, but does not display the desired response.

Ideas?

<!-- Main.asp -->
<HTML>
<HEAD>

<BODY bgcolor=black text=red>

<FORM name=&quot;Formx&quot; method=&quot;post&quot;>
<INPUT name = &quot;X&quot; value=&quot;See Number 1&quot; type=&quot;button&quot; onclick=&quot;Validate(1)&quot; action=&quot;Response1.asp&quot;>
<INPUT name = &quot;Y&quot; value=&quot;See Number 2&quot; type=&quot;button&quot; onclick=&quot;Validate(2)&quot; action=&quot;Response2.asp&quot;>
</FORM>

<script language=&quot;VBScript&quot; type=&quot;text/vbscript&quot;>
<!--
sub Validate(x)

Set TheForm = Document.forms(&quot;Formx&quot;)

select case x
case 1
'if validation ok then
TheForm.Submit
'end if
case 2
'if validation ok then
TheForm.Submit
'end if
end select
end sub
//-->
</script>

</body>
</html>

===================
Files to be called:
===================

Response1.asp
-------------
<% response.write(&quot;1&quot;) %>

Response2.asp
<% response.write(&quot;2&quot;) %>
 
<html>
<head>
<script language=&quot;JavaScript&quot;>
function doSubmit(s){
if (s==1){
document.frmForm.action=&quot;A.asp&quot;;
document.frmForm.submit();
}
else{
document.frmForm.action=&quot;B.asp&quot;;
document.frmForm.submit();
}
}
</script>
</head>

<body >
<form name=&quot;frmForm&quot; action=&quot;#&quot; method=&quot;POST&quot;>
<input type=&quot;text&quot; name=&quot;txt1&quot; >
<input type=&quot;button&quot; value=&quot;submit 1&quot; onclick=&quot;doSubmit(1);&quot;>
<input type=&quot;button&quot; value=&quot;submit 2&quot; onclick=&quot;doSubmit(2);&quot;>
</form>
</body>

</html>
 
Thanks phuctran, works fine. I did have to remove the semicolons though. I would have preferred vbscipt, but for my purposes this will suffice.

I also noticed some errors in my code, and after fixing those, and placing the function in the head portion of the document, I copied your code to a subroutine and translated it to vbscript.

For some unknow reason the vbscript brought up the download window, asking me if I wanted to save the file.

Any help on that would be appreciated.
 
Thanks phuctran, works fine. I did have to remove the semicolons from the INPUT though. I would have preferred vbscipt, but for my purposes this will suffice.

I also noticed some errors in my code, and after fixing those, and placing the function in the head portion of the document, I copied your code to a subroutine and translated it to vbscript.

For some unknow reason the vbscript brought up the download window, asking me if I wanted to save the file.

Any help on that would be appreciated.
 
Here you go:

<!-- Main.asp -->
<HTML>
<HEAD>
<script language=&quot;VBScript&quot; type=&quot;text/vbscript&quot;>
<!--
sub doSubmit(x)

Set TheForm = Document.forms(&quot;Formx&quot;)

select case x
case 1
TheForm.action=&quot;c:\Retal\Response1.asp&quot;
TheForm.Submit
case 2
TheForm.action=&quot;c:\Retal\Response2.asp&quot;
TheForm.Submit
end select
end sub
//-->
</script>

</HEAD>

<BODY bgcolor=black text=red>
<FORM name=&quot;Formx&quot; method=&quot;post&quot; action=&quot;#&quot;>
<INPUT value=&quot;See Number 1&quot; type=&quot;button&quot; onclick=&quot;doSubmit(1)&quot;>
<INPUT value=&quot;See Number 2&quot; type=&quot;button&quot; onclick=&quot;doSubmit(2)&quot;>
</FORM>

</center>
</body>
</html>


<!-- Response1.asp
<% response.write(&quot;1&quot;) %>
-->

<!-- Response2.asp
<% response.write(&quot;2&quot;) %>
-->
 
The VBScript code does indeed work.

After significant investigation I realized that the &quot;File Download Window&quot; problem occurs when I put in a path(e.g. &quot;C:\....&quot;) to an ASP file I want to load.

No problem with HTML using that construct, but my ignorance precluded me from understanding the concept of a server being a logical device rather than a physical one, and files are relative to the logical device,

Many thanks for your help.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top