Solved

OnSubmit  Post Problem

Posted on 1997-04-03
1
909 Views
Last Modified: 2012-08-14
Ok,

Here's the problem.  I am submitting form responses into a database. I am using the OnSubmit Handler and the POST form method.  I call the function (Save It () ) on the form submission.  The posting of the data goes through (because I get returned info from the database) but it will not recognize the form name ( Srch ).  It says Srch not defined.

My question is... Can you use POST and OnSubmit in this manner.  If not how do you go about doing these two things at once ??

Here are the Snippets of code......

-----------------------(The Function)----------------------

<Script Language="javascript">
<!-- Hide it
      function SaveIt ()
        {
        if (Srch.Skills.value.length != 0)
                                           {
        var expdate = new Date ();
        expdate.setTime(expdate.getTime() + (24 * 60 * 60 * 1000));
        SetCookie('Skills',Srch.Skills.value, expdate);
        SetCookie('Phone',Srch.Location.value, expdate);
       SetCookie('Travel_Location',Srch.Travel_Location.value,
expdate);
                                                }
          else
             {
                 alert('You left a field blank.');
                 return false;
             }
         }
// done -->    
</script>

-----------------------(The Code)-------------------------

<form name="Srch" OnSubmit="SaveIt ()" Method="POST" ACTION="http://206.201.123.139/scripts/acc2web.exe">
<FONT FACE="ARIAL,HELVETICA" SIZE="+1">
<CENTER><Table border="3"><td><IMG SRC="fire3.gif"></td></table>
<br>
<br>
</center>
<H2><u>Query Information Area</u></H2>
<br>
<font size="+0">My <i>ideal</i> candidate would....<br><br>
<TABLE BORDER="0">
<TR>
<td align="left">
<INPUT TYPE="hidden" NAME="DbName" VALUE="c:\Webshare\wwwroot\iteam\database\person.mdb">
Have the following skills :
</td>
<td align="left">
<INPUT TYPE=text SIZE=24 NAME="Skills">
---------------------------(End)-------------------------

Thanks !!!!
0
Comment
Question by:dmccarty
1 Comment
 
LVL 3

Accepted Solution

by:
RM032397 earned 70 total points
ID: 1265118
The form name in SaveIt is not enough to define the form which must be window.document.Srch
The short way is to pass a parameter. For onClick and such in INPUTs it would be this.form but for onSubmit, because it is in the FORM tag 'this' will suffice (and equates automatically to window.document.Srch), hence

<form name="Srch" OnSubmit="SaveIt(this)"

Then you can receive the parameter as

function SaveIt(form) {

and within the function ...

 if (form.Skills.value.length != 0)
 
... so all the elements are fully defined objects.

onSubmit functions are independent of SUBMIT, they just happen when the form is submitted. Your js function is failing, while the SUBMIT itself is succeeding. It will not take too long to have it zinging along I hope!
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
Boost your ability to deliver ambitious and competitive web apps by choosing the right JavaScript framework to best suit your project’s needs.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

910 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now