Solved

OnSubmit  Post Problem

Posted on 1997-04-03
1
917 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

Suggested Solutions

In this article, we'll look how to sort an Array in JavaScript, including the more advanced techniques of sorting a collection of records either ascending or descending on two or more fields. Basic Sorting of Arrays First, let's look at the …
In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
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…

815 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

8 Experts available now in Live!

Get 1:1 Help Now