Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

behaviors, HTC, and onSubmit

Posted on 2001-06-18
17
458 Views
Last Modified: 2008-02-07
Hello, I'm trying to write a HTML component that I can
attach a behaviour for the onSubmit event of a form.
 
ie, something like this:

--------------------------------------------------------

<COMPONENT>
<ATTACH EVENT="onsubmit" ONEVENT="ValidateData" />
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
  function ValidateData()
  {
  ... do some validation ...
  }
</SCRIPT>
</COMPONENT>

--------------------------------------------------------

...which is used in the following manner:

--------------------------------------------------------
<STYLE>
  .ValidationForm {behavior:url(ValidationForm.htc)}
</STYLE>
<HTML>
  <FORM CLASS="ValidationForm">
    Income: <INPUT TYPE="text" LENGTH=50 NAME="Income">
    <INPUT TYPE="submit" VALUE="Submit Form">  
  </FORM>
</HTML>
--------------------------------------------------------

Now the trouble is returning false from the ValidateData()
function doesn't seem to cancel the form submission like
it does if I was to do this the 'convential' way using
embedded (or otherwise) script (ie. <FORM onSubmit="return(ValidationForm());">) Is this a limitation, or am I doing something wrong?

Thanks for your help!

Craig
0
Comment
Question by:FancyPants
  • 7
  • 6
  • 2
  • +2
17 Comments
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6204660
You should call the function using return validateData()

That will make the return work...

Cheers,
Max.
0
 

Author Comment

by:FancyPants
ID: 6204663
Thanks Max, I've already tried that with no success.
0
 

Author Comment

by:FancyPants
ID: 6204664
Thanks Max, I've already tried that with no success.
0
How our DevOps Teams Maximize Uptime

Our Dev teams are like yours. They’re continually cranking out code for new features/bugs fixes, testing, deploying, responding to production monitoring events and more. It’s complex. So, we thought you’d like to see what’s working for us. Read the use case whitepaper.

 
LVL 19

Expert Comment

by:DreamMaster
ID: 6204665
So this

<COMPONENT>
<ATTACH EVENT="onsubmit" ONEVENT="ValidateData" />
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
 function ValidateData()
 {
 ... do some validation ...
 }
</SCRIPT>
</COMPONENT>

would become

<COMPONENT>
<ATTACH EVENT="onsubmit" ONEVENT="return ValidateData" />
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
 function ValidateData()
 {
 ... do some validation ...
 }
</SCRIPT>
</COMPONENT>

Cheers,
Max.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6204671
In that case please show me the code you have tried...

Max.
0
 

Author Comment

by:FancyPants
ID: 6204678
Well, if you were just to put a return(false); in the
body of the validateData function of the above code you will notice that the form is still submitted.

Thanks,
Craig.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6204688
Yes...but you need both....return false in the body and the return ValidateData did you do that?

Max.
0
 

Author Comment

by:FancyPants
ID: 6204690
Yep, have tried both.. have tried all different combinations I can think of.. still no joy.

Thanks,
Craig.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6204697
Have never heared of this being a limitation.....there must be something that is going wrong...

Max.
0
 

Author Comment

by:FancyPants
ID: 6204705
Yes, I know, hence my question :) Even if you just put
a return(false); statement in the event handler the form
is still submitted.

Thanks for your help,
Craig.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6204713
I will look up some more information in the morning need to sleep now....

Max.
0
 
LVL 19

Expert Comment

by:DreamMaster
ID: 6205421
Probably the best thing I could tell you to do now..is to create a seperate function that will submit the form...this event will only be triggered when the function gets to that part if not you will simply return to the page as you were...

Max.
0
 
LVL 2

Expert Comment

by:ZhongYu
ID: 6205591
You should use

event.returnVlaue = false;

BTW, I would use:
<attach event="onsubmit" handler="ValidateData"/>
If yours work too, it seems there are so many valid syntaxes.
0
 
LVL 19

Expert Comment

by:webwoman
ID: 6206144
Take out the component and attach tags, see if it works then. If so, then it's because of the way you're using the javascript, NOT because the javascript itself is wrong.

I suspect that might be the case. Not sure though, but it would make sense.
0
 
LVL 2

Accepted Solution

by:
ZhongYu earned 300 total points
ID: 6207428
Sorry for typo, should be:

event.returnValue = false;
0
 

Author Comment

by:FancyPants
ID: 6208602
Exactly what I needed... Thanks ZhongYu.

Craig.
0
 

Expert Comment

by:backdraf
ID: 6740150
<public:component>
<public:attach event="onsubmit" onevent="fnValidate()" />
    <script language="vbscript">
          function fnValidate()
               if element.document.all.txtTest.value = "" then
                    window.event.cancelbubble = true
                    window.event.returnvalue = false
               end if
          end function
    </script>
</public:component>
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
Accurate Analytics (Not Google) 2 60
show form submit button based on jquery sum 5 45
what are list of ebay api errors 1 28
website rewamp 5 42
Any business that wants to seriously grow needs to keep the needs and desires of an international audience of their websites in mind. Making a website friendly to international users isn’t prohibitively expensive and can provide an incredible return…
This article will inform Clients about common and important expectations from the freelancers (Experts) who are looking at your Gig.
Viewers will get an overview of the benefits and risks of using Bitcoin to accept payments. What Bitcoin is: Legality: Risks: Benefits: Which businesses are best suited?: Other things you should know: How to get started:
The viewer will learn how to count occurrences of each item in an array.

829 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