ASP Shopping CartForum & BBS
  - all for $20 from CodeToad Plus!
  Home || ASP | ASP.Net | C++/C# | DHTML | HTML | Java | Javascript | Perl | VB | XML || CodeToad Plus! || Forums || RAM 
Search Site:
Search Forums:
  2 actions from the same form submit buttons - How do I do it?????  czhammond at 20:58 on Wednesday, April 05, 2006


I am a newbie to Javascript and am having a few difficulties!

I am trying to run 2 seperate Javascript functions ("hidden" and "verify") from 1 submit button. Both of these functions have worked successfully when run seperately from the submit button - any ideas how I combine the code.....

Code is:

1) This pulls data from a text box in an iframe and puts it into a hidden text box in my main page form.

function hidden(){
window.document.forms["second"].elements["hiddenmodel"].value = window.frames["pic"].document.forms["frmModel"].elements["model"].value;

2) This runs the hidden function (above) when submit button pressed.

<form method="get" action="asp_add.asp" name="second" onsubmit="hidden()">

3) This validates that data has been input in mandatory fields.

<script language="JavaScript">
function verify(form) {
var errors = "";
var msg = "Your details were not submitted because of the following error(s).\n\n";

if (form.make.value == "" || form.model.value == "") {

errors += " - you must enter selection criteria to proceed." +"\n\n" }

if (errors != "")
alert(msg + errors + "Thank you.")
return false
second.action ="asp_add.asp"
return true

4) This runs the verify function (above) when the submit button is pressed.

<form method="get" name="second" onsubmit="
this.make.optional = true;
this.model.optional = true;
return verify(this);">

Many thanks in advance for any help...


  Re: 2 actions from the same form submit buttons - How do I do it?????  Jeff Anderson at 08:26 on Thursday, April 06, 2006

Hi Cathy
Not entirely sure I understand what you're after, but can't you simply create a third function, and then onsubmit of the form call both the other functions from there?

as in

function formsubmit(form)

<form method="get" name="second" onsubmit="
this.make.optional = true;
this.model.optional = true;
return formsubmit(this);">


sorry the formsubmit function should probably be

function formsubmit(form)
return verify(form)

  Re: 2 actions from the same form submit buttons - How do I do it?????  czhammond at 11:02 on Thursday, April 06, 2006

Hi Jeff - Many thanks for your quick response.

I have amended the onsubmit to run a new function that calls my hidden and verify functions, as you suggested, but it doesn't work.

The verify function doesn't pick up empty mandatory fields and the hidden function doesn't copy a value into a hidden field, which should be sent in the URL to page asp_add.asp. When submit is pressed, the current page (upd_search.asp) is refreshed and passed some empty querystring parameters.

Both the verify function and the hidden function are tried and tested running seperately from the submit button.

The hidden function has always been coded in <script> tags within the <head>. The verify function within <script language="JavaScript"> tags within the body. Does this make any difference? Which tags should my new formsubmit function be within?

Any help much appreciated, as my PC is heading towards the open window as we speak! ;-)


CodeToad Experts

Can't find the answer?
Our Site experts are answering questions for free in the CodeToad forums

Recent Forum Threads
• Game:Colonization based with HTML5 Canvas and JavaScript
• Pointwise.GridGen.v15.18
• Global.Mapper.v15.2.3.b060614
• Geometric_Glovius_Pro_v3.6.1
• VERO.SurfCAM.v2014
• Schlumberger.Petrel.V2013.2
• Petrel.V2013.2
• Altair.HyperWorks.v12
• VoluMill.v6.1

Recent Articles
ASP GetTempName
Decode and Encode UTF-8
ASP GetFile
ASP FolderExists
ASP FileExists
ASP OpenTextFile
ASP FilesystemObject
ASP CreateFolder
ASP CreateTextFile
Javascript Get Selected Text

© Copyright 2001-2014