Solved

OnSubmit  Post Problem

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

How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

Join & Write a Comment

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 …
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
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…

762 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