onSubmit and Internet Explorer = trouble

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

    onSubmit and Internet Explorer = trouble

    I have a form that uses the following: onSubmit="some_ var =
    'validated';"

    FireFox is OK with that. Internet Explorer isn't. any ideas why?

    Thanks.
  • VK

    #2
    Re: onSubmit and Internet Explorer = trouble

    On Jun 1, 10:53 am, Mark Livingstone <namematters... @msn.comwrote:
    I have a form that uses the following: onSubmit="some_ var =
    'validated';"
    >
    FireFox is OK with that. Internet Explorer isn't. any ideas why?
    This code assigns to global variable some_var string value "validated"
    and then submits the form so causing new page load with the Javascript
    context being reset: so it doesn't matter what value to what do you
    assign before that. I don't know what browser and how could be "OK
    with that" - you have to explain then what does it mean OK and most
    helpful: what are you trying to achieve overall.

    Comment

    • Mark Livingstone

      #3
      Re: onSubmit and Internet Explorer = trouble

      On Jun 1, 4:23 am, VK <schools_r...@y ahoo.comwrote:
      On Jun 1, 10:53 am, Mark Livingstone <namematters... @msn.comwrote:
      >
      I have a form that uses the following: onSubmit="some_ var =
      'validated';"
      >
      FireFox is OK with that. Internet Explorer isn't. any ideas why?
      >
      This code assigns to global variable some_var string value "validated"
      and then submits the form so causing new page load with the Javascript
      context being reset: so it doesn't matter what value to what do you
      assign before that. I don't know what browser and how could be "OK
      with that" - you have to explain then what does it mean OK and most
      helpful: what are you trying to achieve overall.
      I am using jQuery Forms script to bind to the submit action. so, when
      the onSubmit fires, the script picks it up, runs a certain function
      and prevents the form from being submitted using the regular POST
      method -- it does that using jQuery's AJAX post method. page doesn't
      refresh and JS context is not reset. So, FF is OK with that syntax and
      I can recognize the value of some_var but IE doesn't.

      Comment

      • Mark Livingstone

        #4
        Re: onSubmit and Internet Explorer = trouble

        Forgot to mention... if I create a function that assigns a value to
        some_var and then do onSubmit="funct ion();", everything works fine.
        It's just that IE doesn't want to recognize onSubmit="some_ var =
        'value';" or onSubmit="somev ar = 1;" syntax.

        Comment

        • VK

          #5
          Re: onSubmit and Internet Explorer = trouble

          On Jun 1, 7:48 pm, Mark Livingstone <namematters... @msn.comwrote:
          Forgot to mention... if I create a function that assigns a value to
          some_var and then do onSubmit="funct ion();", everything works fine.
          It's just that IE doesn't want to recognize onSubmit="some_ var =
          'value';" or onSubmit="somev ar = 1;" syntax.
          If somewhere after page load you do like
          document.forms[0].onsubmit = validate;
          then it is not important what do you have in the form intrinsic event
          listener because it gets overridden. If you have
          <form ... onsubmit="some_ var='value';">
          then this listener is being overriden so never called. This is
          consistent across browsers including Firefox, so whatever it is "OK
          with that" - it is not what you are describing in this thread. If you
          need to assign a value and call form validator and prevent form
          submission if not validated then you could use something like:
          <form ... onsubmit="retur n validate(some_v ar='value')">

          Comment

          • Evertjan.

            #6
            Re: onSubmit and Internet Explorer = trouble

            VK wrote on 01 jun 2008 in comp.lang.javas cript:
            On Jun 1, 10:53 am, Mark Livingstone <namematters... @msn.comwrote:
            >I have a form that uses the following: onSubmit="some_ var =
            >'validated'; "
            >>
            >FireFox is OK with that. Internet Explorer isn't. any ideas why?
            >
            This code assigns to global variable some_var string value "validated"
            and then submits the form so causing new page load with the Javascript
            context being reset: so it doesn't matter what value to what do you
            assign before that.
            This is not always true, VK, try this:

            <form onSubmit="some_ var = 'validated';" target='_blank' ...

            And could be usefully used like this:

            =============== =============== ============
            <form onSubmit="retur n submitOnlyOnce( )" target='_blank' ...

            <script type='text/javascript'>
            var submitted = false;
            function submitOnlyOnce( ) {
            if (submitted) return false;
            return submitted = true;
            };
            </script>
            =============== =============== ============


            --
            Evertjan.
            The Netherlands.
            (Please change the x'es to dots in my emailaddress)

            Comment

            • VK

              #7
              Re: onSubmit and Internet Explorer = trouble

              On Jun 2, 1:51 am, "Evertjan." <exjxw.hannivo. ..@interxnl.net wrote:
              VK wrote on 01 jun 2008 in comp.lang.javas cript:
              >
              On Jun 1, 10:53 am, Mark Livingstone <namematters... @msn.comwrote:
              I have a form that uses the following: onSubmit="some_ var =
              'validated';"
              >
              FireFox is OK with that. Internet Explorer isn't. any ideas why?
              >
              This code assigns to global variable some_var string value "validated"
              and then submits the form so causing new page load with the Javascript
              context being reset: so it doesn't matter what value to what do you
              assign before that.
              >
              This is not always true, VK, try this:
              >
              <form onSubmit="some_ var = 'validated';" target='_blank' ...
              >
              And could be usefully used like this:
              >
              =============== =============== ============
              <form onSubmit="retur n submitOnlyOnce( )" target='_blank' ...
              >
              <script type='text/javascript'>
              var submitted = false;
              function submitOnlyOnce( ) {
              if (submitted) return false;
              return submitted = true;};
              >
              </script>
              =============== =============== ============
              You missed the point: of course the intrinsic event handler can be
              most useful. I explained that one cannot have two unrelated blocks in
              both DOM interface handler and in intrinsic handler: one will be
              ignored, namely the intrinsic one.

              Doesn't work:

              ....
              document.forms[0].onsubmit = validate;
              ....
              <form ... onsubmit="some_ var='value';/* will be ignored */">


              Workaround 1:

              document.forms[0].onsubmit = function() {
              some_var='value ';
              return validate(this);
              }

              Workaround 2:

              <form ... onsubmit="some_ var='value'; return validate(this); ">

              If some_var is indeed some additional "submission allowed" flag then
              it could be even:

              <form ... onsubmit="retur n some_var : validate(this); ">

              There is a number of other options but nothing of what OP was trying
              to do: it is simply not supported.

              Comment

              • VK

                #8
                Re: onSubmit and Internet Explorer = trouble

                On Jun 2, 2:17 am, VK <schools_r...@y ahoo.comwrote:
                If some_var is indeed some additional "submission allowed" flag then
                it could be even:
                >
                <form ... onsubmit="retur n some_var : validate(this); ">
                A rush of typing, sorry, of course:

                <form ... onsubmit="retur n some_var ? true : validate(this); ">
                or
                <form ... onsubmit="retur n some_var ? false : validate(this); ">

                depending on some_var being allowing or blocking flag.

                Comment

                • Thomas 'PointedEars' Lahn

                  #9
                  Re: onSubmit and Internet Explorer = trouble

                  VK wrote:
                  On Jun 2, 2:17 am, VK <schools_r...@y ahoo.comwrote:
                  >If some_var is indeed some additional "submission allowed" flag then
                  >it could be even:
                  >>
                  ><form ... onsubmit="retur n some_var : validate(this); ">
                  >
                  A rush of typing, sorry, of course:
                  >
                  <form ... onsubmit="retur n some_var ? true : validate(this); ">
                  or
                  <form ... onsubmit="retur n some_var ? false : validate(this); ">
                  >
                  depending on some_var being allowing or blocking flag.
                  A more reasonable and more efficient approach would be

                  <form ... onsubmit="retur n !!some_var || validate(this); ">
                  or
                  <form ... onsubmit="retur n !some_var && validate(this); ">

                  or using some_var in a gauntlet within validate().


                  PointedEars
                  --
                  Anyone who slaps a 'this page is best viewed with Browser X' label on
                  a Web page appears to be yearning for the bad old days, before the Web,
                  when you had very little chance of reading a document written on another
                  computer, another word processor, or another network. -- Tim Berners-Lee

                  Comment

                  Working...