Hooking into page's onsubmit event from code within page?

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • planetthoughtful

    #1

    Hooking into page's onsubmit event from code within page?

    Hi All,

    Where I work we're using a reasonably basic tool to build web pages
    and forms, that doesn't allow us to edit any source HTML and doesn't
    allow us to access header content or the <BODYtags at all.

    We've discovered that one of the 'field types' we can add to a form
    will allow us to include javascript functions and also HTML elements
    that appear to be accurately interpreted when the page is rendered,
    but our most pressing need at the moment is to be able to figure out a
    way to perform form field validation of the form controls when the
    page is submitted.

    As above, I can't edit any of the properties of the submit button
    itself, and can't edit properties of the BODY tag or anything that
    appears within the HEAD tags. I can only insert Javascript as a text
    element into the page itself.

    Does anyone know if I can implement some javascript that gets run when
    the page is loaded that enforces running of another javascript
    function when the page is submitted?

    Any help much appreciated!!

    pt
  • Kiran Makam

    #2
    Re: Hooking into page's onsubmit event from code within page?

    On Oct 3, 6:57 am, planetthoughtfu l <planetthought. ..@gmail.com>
    wrote:
    but our most pressing need at the moment is to be able to figure out a
    way to perform form field validation of the form controls when the
    page is submitted.
    Try this:
    -------------
    function addEvtLis(o, type, handler) {
    if(o.attachEven t) {
    o.attachEvent(" on" + type, handler);
    }
    else if(o.addEventLi stener) {
    o.addEventListe ner(type, handler, false);
    }
    }

    function formOnSubmitHan dler(evt){
    var validationPasse d = true;

    //your code

    //prevent form submission
    if( !validationPass ed ){
    if(evt.preventD efault) evt.preventDefa ult();
    evt.returnValue = false;
    }
    }

    //set handler for form submit
    addEvtLis(docum ent.myFormName, "submit", formOnSubmitHan dler);
    --------------

    >I can only insert Javascript as a text element into the page itself
    Hope script tags are intact, otherwise no javascript will work.

    Does anyone know if I can implement some javascript that gets run when
    the page is loaded that enforces running of another javascript
    function when the page is submitted?
    --------
    function pageOnLoadHandl er(evt){
    //your code
    }

    //set handler for window on load
    addEvtLis(windo w, "load", pageOnLoadHandl er);
    -------

    - Kiran Makam

    Comment

    • planetthoughtful

      #3
      Re: Hooking into page's onsubmit event from code within page?


      On Oct 3, 3:40 pm, Kiran Makam <kiranm...@gmai l.comwrote:
      On Oct 3, 6:57 am, planetthoughtfu l <planetthought. ..@gmail.com>
      wrote:
      >
      but our most pressing need at the moment is to be able to figure out a
      way to perform form field validation of the form controls when the
      page is submitted.
      >
      Try this:
      -------------
      function addEvtLis(o, type, handler) {
          if(o.attachEven t) {
              o.attachEvent(" on" + type, handler);
          }
          else if(o.addEventLi stener) {
              o.addEventListe ner(type, handler, false);
          }
      >
      }
      >
      function formOnSubmitHan dler(evt){
          var validationPasse d = true;
      >
          //your code
      >
          //prevent form submission
          if( !validationPass ed ){
              if(evt.preventD efault) evt.preventDefa ult();
              evt.returnValue = false;
          }
      >
      }
      >
      //set handler for form submit
      addEvtLis(docum ent.myFormName, "submit", formOnSubmitHan dler);
      --------------
      >
      I can only insert Javascript as a text element into the page itself
      >
      Hope script tags are intact, otherwise no javascript will work.
      >
      Does anyone know if I can implement some javascript that gets run when
      the page is loaded that enforces running of another javascript
      function when the page is submitted?
      >
      --------
      function pageOnLoadHandl er(evt){
          //your code
      >
      }
      >
      //set handler for window on load
      addEvtLis(windo w, "load", pageOnLoadHandl er);
      -------
      >
      - Kiran Makam
      Hi Kiran,

      I should have mentioned that your solution hit the spot exactly!

      Thank you very much!

      pt

      Comment

      • David Mark

        #4
        Re: Hooking into page's onsubmit event from code within page?

        On Oct 3, 1:40 am, Kiran Makam <kiranm...@gmai l.comwrote:
        On Oct 3, 6:57 am, planetthoughtfu l <planetthought. ..@gmail.com>
        wrote:
        >
        but our most pressing need at the moment is to be able to figure out a
        way to perform form field validation of the form controls when the
        page is submitted.
        >
        Try this:
        -------------
        function addEvtLis(o, type, handler) {
            if(o.attachEven t) {
                o.attachEvent(" on" + type, handler);
            }
            else if(o.addEventLi stener) {
                o.addEventListe ner(type, handler, false);
            }
        >
        }
        Always use typeof to test host object methods.
        >
        function formOnSubmitHan dler(evt){
            var validationPasse d = true;
        >
            //your code
        >
            //prevent form submission
            if( !validationPass ed ){
                if(evt.preventD efault) evt.preventDefa ult();
                evt.returnValue = false;
        Don't augment host objects.

        Comment

        • sasuke

          #5
          Re: Hooking into page's onsubmit event from code within page?

          On Oct 13, 10:29 am, David Mark <dmark.cins...@ gmail.comwrote:
          On Oct 3, 1:40 am, Kiran Makam <kiranm...@gmai l.comwrote:
          >
          >
          >
          On Oct 3, 6:57 am, planetthoughtfu l <planetthought. ..@gmail.com>
          wrote:
          >
          but our most pressing need at the moment is to be able to figure out a
          way to perform form field validation of the form controls when the
          page is submitted.
          >
          Try this:
          -------------
          function addEvtLis(o, type, handler) {
              if(o.attachEven t) {
                  o.attachEvent(" on" + type, handler);
              }
              else if(o.addEventLi stener) {
                  o.addEventListe ner(type, handler, false);
              }
          >
          }
          >
          Always use typeof to test host object methods.
          Is there any case where a typeof would have distinct benefit over the
          way Kiran has done?
          function formOnSubmitHan dler(evt){
              var validationPasse d = true;
          >
              //your code
          >
              //prevent form submission
              if( !validationPass ed ){
                  if(evt.preventD efault) evt.preventDefa ult();
                  evt.returnValue = false;
          >
          Don't augment host objects.
          Don't `supplement/overuse' host objects? [Sorry, but English isn't my
          first language]

          /sasuke

          Comment

          • David Mark

            #6
            Re: Hooking into page's onsubmit event from code within page?

            On Oct 13, 12:13 pm, sasuke <database...@gm ail.comwrote:
            On Oct 13, 10:29 am, David Mark <dmark.cins...@ gmail.comwrote:
            >
            >
            >
            On Oct 3, 1:40 am, Kiran Makam <kiranm...@gmai l.comwrote:
            >
            On Oct 3, 6:57 am, planetthoughtfu l <planetthought. ..@gmail.com>
            wrote:
            >
            but our most pressing need at the moment is to be able to figure out a
            way to perform form field validation of the form controls when the
            page is submitted.
            >
            Try this:
            -------------
            function addEvtLis(o, type, handler) {
                if(o.attachEven t) {
                    o.attachEvent(" on" + type, handler);
                }
                else if(o.addEventLi stener) {
                    o.addEventListe ner(type, handler, false);
                }
            >
            }
            >
            Always use typeof to test host object methods.
            >
            Is there any case where a typeof would have distinct benefit over the
            way Kiran has done?
            >
            function formOnSubmitHan dler(evt){
                var validationPasse d = true;
            >
                //your code
            >
                //prevent form submission
                if( !validationPass ed ){
                    if(evt.preventD efault) evt.preventDefa ult();
                    evt.returnValue = false;
            >
            Don't augment host objects.
            >
            Don't `supplement/overuse' host objects? [Sorry, but English isn't my
            first language]
            >
            /sasuke
            Don't add arbitrary properties to host objects. Treat them like they
            are from another planet (and very sensitive.)

            At the very least, an else should be added to the nested if.

            Comment

            Working...