submitting form through javascript

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

    submitting form through javascript

    Hi all
    I have a page which contains a form.
    I want a customized button with an image for the submit button, and when the
    submit button has been clicked send the form to the perl script.
    Now the form is no problem but the button is, so the question is how do I
    create a custom button and how do I submit the form with javascript when the
    button is clicked?
    many thank's for any hint and help
    B


  • Fred Serry

    #2
    Re: submitting form through javascript


    "Bob Smith" <bob_smith85@ho tmail.com> schreef in bericht
    news:85j6b.3866 $ZB4.1965@reade r1.news.jippii. net...[color=blue]
    > Hi all
    > I have a page which contains a form.
    > I want a customized button with an image for the submit button, and when[/color]
    the[color=blue]
    > submit button has been clicked send the form to the perl script.
    > Now the form is no problem but the button is, so the question is how do I
    > create a custom button and how do I submit the form with javascript when[/color]
    the[color=blue]
    > button is clicked?
    > many thank's for any hint and help
    > B
    >
    >[/color]

    Hi

    Why use javascript? <input type=image> does what you want



    Fred


    Comment

    • Bob Smith

      #3
      Re: submitting form through javascript

      > >[color=blue]
      >
      > Hi
      >
      > Why use javascript? <input type=image> does what you want[/color]
      thank's
      but it doesn't work as expected,
      the form is not submitted
      ( browser netscape 4.7x)
      any help much appreciated.
      B
      [color=blue]
      >
      >[/color]

      erence/objects/input_image.asp[color=blue]
      >
      > Fred
      >
      >[/color]


      Comment

      • Sean Jorden

        #4
        Re: submitting form through javascript

        "Bob Smith" <bob_smith85@ho tmail.com> wrote in
        news:y6k6b.3890 $ZB4.3886@reade r1.news.jippii. net:
        [color=blue][color=green][color=darkred]
        >> >[/color]
        >>
        >> Hi
        >>
        >> Why use javascript? <input type=image> does what you want[/color]
        > thank's
        > but it doesn't work as expected,
        > the form is not submitted
        > ( browser netscape 4.7x)
        > any help much appreciated.
        > B
        >[/color]

        dude, seriously. The following two are equivalent:

        <input type="image" src="some_image .gif" name="submit" />
        <input type="submit" name="submit.x" />

        they will both submit the form.. I would hazard to guess this even works on
        Netscape 2.0. Of course .. you need an actual GIF to make the button.


        --
        In theory there is no difference between theory and practice. In practice
        there is. - YB

        Comment

        • Bart Van der Donck

          #5
          Re: submitting form through javascript

          "Bob Smith" <bob_smith85@ho tmail.com> wrote in message news:<85j6b.386 6$ZB4.1965@read er1.news.jippii .net>...[color=blue]
          > Hi all
          > I have a page which contains a form.
          > I want a customized button with an image for the submit button, and when the
          > submit button has been clicked send the form to the perl script.
          > Now the form is no problem but the button is, so the question is how do I
          > create a custom button and how do I submit the form with javascript when the
          > button is clicked?
          > many thank's for any hint and help
          > B[/color]


          Bob,

          You want something like:

          <form method="post" action="myperl. script">
          <button onClick="docume nt.forms[0].submit()">
          <img src="http://www.microsoft.c om/homepage/gif/bnr-microsoft.gif"
          width="250" height="60">
          </button>
          </form>

          It is possible that images inside buttons are Internet Explorer only,
          not sure.

          Regards
          Bart

          Comment

          • Richard Cornford

            #6
            Re: submitting form through javascript

            "Bart Van der Donck" <bart@nijlen.co m> wrote in message
            news:b5884818.0 309060456.4ba53 cb5@posting.goo gle.com...
            <snip>[color=blue]
            >
            > You want something like:
            >
            > <form method="post" action="myperl. script">
            > <button onClick="docume nt.forms[0].submit()">
            > <img src="http://www.microsoft.c om/homepage/gif/bnr-microsoft.gif"
            > width="250" height="60">
            > </button>
            > </form>[/color]

            No you don't. As the desired effect can be achieved with pure HTML that
            is how it should be achieved, but the default type of a BUTTON element
            is "submit" anyway so even this option would work as pure HTML if you
            take the JavaScript onclick attribute out.
            [color=blue]
            > It is possible that images inside buttons are Internet Explorer only,
            > not sure.[/color]

            Netscape 4 does not recognise the BUTTON element at all (because it was
            introduced with HTML 4) but I think that images are OK as content
            everywhere that BUTTON is recognised (though ALT text becomes very
            relevant in speech/text browsers (and is required on IMG elements in
            HTML 4 anyway)).

            Richard.


            Comment

            • Bart Van der Donck

              #7
              Re: submitting form through javascript

              "Richard Cornford" <Richard@litote s.demon.co.uk> wrote...
              [color=blue][color=green]
              > > You want something like:
              > >
              > > <form method="post" action="myperl. script">
              > > <button onClick="docume nt.forms[0].submit()">
              > > <img src="http://www.microsoft.c om/homepage/gif/bnr-microsoft.gif"
              > > width="250" height="60">
              > > </button>
              > > </form>[/color]
              >
              > No you don't. As the desired effect can be achieved with pure HTML that
              > is how it should be achieved, but the default type of a BUTTON element
              > is "submit" anyway so even this option would work as pure HTML if you
              > take the JavaScript onclick attribute out.[/color]

              <button type="submit"> would work too, yes. It are just 2 ways to
              achieve the same goal. Is that why Bob shouldn't use my code ?
              However, by just taking the onClick event away, the form doesn't
              submit (just quick test on IE6 here) as you say.

              [color=blue][color=green]
              > > It is possible that images inside buttons are Internet Explorer only,
              > > not sure.[/color]
              >
              > Netscape 4 does not recognise the BUTTON element at all (because it was
              > introduced with HTML 4) but I think that images are OK as content
              > everywhere that BUTTON is recognised (though ALT text becomes very
              > relevant in speech/text browsers (and is required on IMG elements in
              > HTML 4 anyway)).[/color]

              Is ALT required on IMG elements in HTML4 ? No it is not.
              About speech/text browsers: yes of course in those cases it is
              relevant, or relevant as info for surfers, or when download fails or
              ....etc

              I never met a textbrowser in my logs however. Not sure about speech
              browsers, but, fairly, I would be surprised.

              Bart

              Comment

              • HikksNotAtHome

                #8
                Re: submitting form through javascript

                In article <b5884818.03090 71141.53557e6@p osting.google.c om>, bart@nijlen.com
                (Bart Van der Donck) writes:
                [color=blue]
                >Is ALT required on IMG elements in HTML4 ? No it is not.[/color]

                HTML4.01:


                alt %Text; #REQUIRED -- short description --

                HTML4.0:

                alt %Text; #REQUIRED -- short description --


                Both say it *is* required.
                --
                Randy

                Comment

                • Richard Cornford

                  #9
                  Re: submitting form through javascript

                  "Bart Van der Donck" <bart@nijlen.co m> wrote in message
                  news:b5884818.0 309071141.53557 e6@posting.goog le.com...
                  <snip>[color=blue]
                  ><button type="submit"> would work too, yes. It are just 2 ways to
                  >achieve the same goal. Is that why Bob shouldn't use my code ?[/color]

                  A scripted HTML page requires support for HTML and JavaScript on the
                  browser. An HTML submit button (of any sort) only requires support for
                  HTML. If exactly the same effect can be achieved reliably with pure HTML
                  it is insane to use JavaScript when the browser pretty much has to have
                  HTML but may not have JavaScript either available or enabled. If it
                  exists, the reliable method is the best.
                  [color=blue]
                  >However, by just taking the onClick event away, the form doesn't
                  >submit (just quick test on IE6 here) as you say.[/color]

                  <quote frome="W3C HTML 4.01 Specification"
                  cite="http://www.w3.org/TR/html4/interact/forms.html#h-17.5">
                  ....
                  <!ATTLIST BUTTON
                  %attrs; -- %coreattrs, %i18n, %events --
                  name CDATA #IMPLIED
                  value CDATA #IMPLIED -- sent to server when
                  submitted --
                  type (button|submit| reset) submit -- for use as form button --
                  ....
                  type = submit|button|r eset [CI]
                  This attribute declares the type of the button. Possible values:
                  submit: Creates a submit button. This is the default value.
                  reset: Creates a reset button.
                  button: Creates a push button.
                  ....
                  </quote>

                  If the HTML spec says it should then IE (or your code) is at fault.

                  <snip>[color=blue][color=green]
                  >> ... (and is required on IMG elements in HTML 4 anyway)).[/color]
                  >
                  >Is ALT required on IMG elements in HTML4 ? No it is not.[/color]

                  Yes it is!
                  [color=blue]
                  >About speech/text browsers: yes of course in those cases it is
                  >relevant, or relevant as info for surfers, or when download fails or
                  >...etc
                  >
                  >I never met a textbrowser in my logs however. Not sure
                  >about speech browsers, but, fairly, I would be surprised.[/color]

                  Logs do not represent an accurate source of information about web
                  browsers, only about the user agent strings that those browsers choose
                  to broadcast (and these days that is often a matter of choice).

                  Which cave first, the site that is inaccessible to text browsers or the
                  fact that no text browsers visit it?

                  Richard.


                  Comment

                  • Bart Van der Donck

                    #10
                    Re: submitting form through javascript

                    Theoretically, you are right.
                    Pactically, interpretations of some W3C specs are possible. And that
                    is how it should be.

                    E.g. HTML4+:

                    W3C specification:
                    default type <button> is "submit"
                    Reality:
                    IE6 doesn't set <button> as "submit" by default
                    Conclusion:
                    Don't use that code

                    W3C specification:
                    ALT is required for IMG
                    Reality:
                    ALT is not required, but recommended
                    Conclusion:
                    You don't need to write ALTs for every IMG
                    [color=blue]
                    > Logs do not represent an accurate source of information about web
                    > browsers, only about the user agent strings that those browsers choose
                    > to broadcast (and these days that is often a matter of choice).[/color]

                    The accuracy is reasonable.

                    Bart

                    Comment

                    • Jim Ley

                      #11
                      Re: submitting form through javascript

                      On 8 Sep 2003 02:30:20 -0700, bart@nijlen.com (Bart Van der Donck)
                      wrote:[color=blue]
                      >IE6 doesn't set <button> as "submit" by default
                      >Conclusion:
                      >Don't use that code[/color]

                      Relying on defaults is never wise, adding type="submit" hardly costs
                      anything.
                      [color=blue]
                      >ALT is not required, but recommended
                      >Conclusion:
                      >You don't need to write ALTs for every IMG[/color]

                      The situation is far from the same, your first one is a bug in a
                      browser if it's not handled properly, missing ALT is an invalid
                      document, which is quite different.
                      [color=blue][color=green]
                      >> Logs do not represent an accurate source of information about web
                      >> browsers, only about the user agent strings that those browsers choose
                      >> to broadcast (and these days that is often a matter of choice).[/color]
                      >
                      >The accuracy is reasonable.[/color]

                      Please define reasonable, and put some accurate metrics on it, for a
                      particular site.

                      Jim.
                      --
                      comp.lang.javas cript FAQ - http://jibbering.com/faq/

                      Comment

                      • Bart Van der Donck

                        #12
                        Re: submitting form through javascript

                        jim@jibbering.c om (Jim Ley) wrote in message news:<3f5c4c6f. 40951214@news.z en.co.uk>...[color=blue]
                        > On 8 Sep 2003 02:30:20 -0700, bart@nijlen.com (Bart Van der Donck)
                        > wrote:[color=green]
                        > >IE6 doesn't set <button> as "submit" by default
                        > >Conclusion:
                        > >Don't use that code[/color]
                        >
                        > Relying on defaults is never wise, adding type="submit" hardly costs
                        > anything.[/color]

                        Agreed

                        [color=blue][color=green]
                        > >ALT is not required, but recommended
                        > >Conclusion:
                        > >You don't need to write ALTs for every IMG[/color]
                        >
                        > The situation is far from the same, your first one is a bug in a
                        > browser if it's not handled properly, missing ALT is an invalid
                        > document, which is quite different.[/color]

                        Agreed... Both examples were only to demonstrate that W3C
                        specifications of HTML4 are sometimes not enough as base for webpage
                        coding. Instead I use something like
                        (1) define which browsers I want to write for
                        (2) within (1) check as much browsers as possible (or available)
                        before putting the code into use

                        [color=blue]
                        >[color=green][color=darkred]
                        > >> Logs do not represent an accurate source of information about web
                        > >> browsers, only about the user agent strings that those browsers choose
                        > >> to broadcast (and these days that is often a matter of choice).[/color]
                        > >
                        > >The accuracy is reasonable.[/color]
                        >
                        > Please define reasonable, and put some accurate metrics on it, for a
                        > particular site.[/color]

                        Reasonable = system administrators have a more or less correct view on
                        what browsers visit the webserver. It must be possible to broadcast a
                        different user-agent as Richard says. However that should be a
                        miniscul minority of the surfing crowd.

                        Bart

                        Comment

                        • Jim Ley

                          #13
                          Re: submitting form through javascript

                          On 8 Sep 2003 08:46:14 -0700, bart@nijlen.com (Bart Van der Donck)
                          wrote:
                          [color=blue]
                          > Both examples were only to demonstrate that W3C
                          >specificatio ns of HTML4 are sometimes not enough as base for webpage
                          >coding.[/color]

                          Marking up invalid sites is unquestionably pointless, believing valid
                          sites are all you should do is also pointless, but valid mark-up
                          doesn't prevent anything, and will catch an awful lot of errors.
                          [color=blue]
                          > Instead I use something like
                          >(1) define which browsers I want to write for[/color]

                          What on incredibly odd way to develop, why not author for the web?
                          [color=blue]
                          >(2) within (1) check as much browsers as possible (or available)
                          >before putting the code into use[/color]

                          So you only do any QA with the old browsers, sounds an odd way of
                          doing QA - I bet you charge more for your "maintenanc e" yeah?
                          [color=blue][color=green]
                          >> Please define reasonable, and put some accurate metrics on it, for a
                          >> particular site.[/color]
                          >
                          >Reasonable = system administrators have a more or less correct view on
                          >what browsers visit the webserver. It must be possible to broadcast a
                          >different user-agent as Richard says. However that should be a
                          >miniscul minority of the surfing crowd.[/color]

                          No, it's the majority, in fact you probably won't find a UA which
                          tells the truth... Of course they might do somewhere in the string
                          aswell as the lies, but then you're relying on the strength of your
                          measuring script, I've yet to see a good one. Also of course people
                          reaching your webserver has little to do with people viewing your
                          site, and then there's the self-fulfilling aspect of logs. Could you
                          explain why you believe the logs are "more and less accurate" ?

                          Jim.
                          --
                          comp.lang.javas cript FAQ - http://jibbering.com/faq/

                          Comment

                          • Richard Cornford

                            #14
                            Re: submitting form through javascript

                            "Bart Van der Donck" <bart@nijlen.co m> wrote in message
                            news:b5884818.0 309080130.40807 ded@posting.goo gle.com...[color=blue]
                            >Theoreticall y, you are right.
                            >Pactically, interpretations of some W3C specs are possible.
                            >And that is how it should be.[/color]

                            A specification that is open to interpretation is a bad specification.
                            But is the phrase "This is the default value" really that unspecific? Or
                            the word "REQUIRED" in the DTD next to the ALT attribute on IMG?
                            [color=blue]
                            > E.g. HTML4+:
                            >
                            > W3C specification:
                            > default type <button> is "submit"
                            > Reality:
                            > IE6 doesn't set <button> as "submit" by default
                            > Conclusion:
                            > Don't use that code[/color]

                            Yes, <input type="image"> is better supported.
                            [color=blue]
                            > W3C specification:
                            > ALT is required for IMG
                            > Reality:
                            > ALT is not required, but recommended[/color]

                            Hence the use of the word "Required" in the DTD.
                            [color=blue]
                            > Conclusion:
                            > You don't need to write ALTs for every IMG[/color]

                            To Author valid HTML 4 every image does need to have an ALT attribute.
                            [color=blue][color=green]
                            >>Logs do not represent an accurate source of information about
                            >>web browsers, only about the user agent strings that those
                            >>browsers choose to broadcast (and these days that is often a
                            >>matter of choice).[/color]
                            >
                            > The accuracy is reasonable.[/color]

                            Logs will accurately report the user agent strings broadcast by
                            client-side software. User agent strings are _not_ an accurate indicator
                            of the nature of he client-side software.

                            Richard.


                            Comment

                            • Bart Van der Donck

                              #15
                              Re: submitting form through javascript

                              jim@jibbering.c om (Jim Ley) wrote in message news:<3f5ca489. 63505265@news.c is.dfn.de>...[color=blue]
                              > On 8 Sep 2003 08:46:14 -0700, bart@nijlen.com (Bart Van der Donck)
                              > wrote:
                              >[color=green]
                              > > Both examples were only to demonstrate that W3C
                              > >specificatio ns of HTML4 are sometimes not enough as base for webpage
                              > >coding.[/color]
                              >
                              > Marking up invalid sites is unquestionably pointless, believing valid
                              > sites are all you should do is also pointless, but valid mark-up
                              > doesn't prevent anything, and will catch an awful lot of errors.
                              >[color=green]
                              > > Instead I use something like
                              > >(1) define which browsers I want to write for[/color]
                              >
                              > What on incredibly odd way to develop, why not author for the web?
                              >[color=green]
                              > >(2) within (1) check as much browsers as possible (or available)
                              > >before putting the code into use[/color]
                              >
                              > So you only do any QA with the old browsers, sounds an odd way of
                              > doing QA - I bet you charge more for your "maintenanc e" yeah?[/color]

                              Authoring for the web is a nice idea, but... where are the limits?
                              Going back to 3+ browsers? Being accessible for LYNX ? It could give a
                              nice feeling that your site is LYNX-compatible, but is it really
                              useful? I doubt

                              I am mostly active in field of web applications and I usually require
                              IE5+. This gives me enough space to use some client script, xml, css2,
                              tabular controls and so. Other browsers get an error message "You need
                              IE5+ to continue". Most of my work consists out of customer login,
                              intranets etc. and until now I never had someone complaining like "but
                              I use Netscape 2!!" or so :-) People with that kind of old browsers
                              mostly have other browsers as well; they know what they are browsing
                              with and know what to expect.

                              I believe it's not odd to develop that way. It is a matter of what is
                              required for what type of thing you want to do. LOT of databases with
                              browser interfaces set requirements. Especially when it comes to
                              intra/extranet usage. There is no other choice if you want to use more
                              complex client scripting.

                              Of course when developing an "average" website for the public, the
                              idea must be totally different and it must be compatible for more
                              browsers. Basically that is a matter of choice of the webmaster - one
                              says "IE4+ NS4+" other says "HTML3+" other says "800*600+" etc. For
                              public websites I use something like IE4+ NS4+ 640*480. Now we're not
                              gonna discuss whether or not that should be HTML3+ or so, OK ;-)
                              [color=blue]
                              >[color=green][color=darkred]
                              > >> Please define reasonable, and put some accurate metrics on it, for a
                              > >> particular site.[/color]
                              > >
                              > >Reasonable = system administrators have a more or less correct view on
                              > >what browsers visit the webserver. It must be possible to broadcast a
                              > >different user-agent as Richard says. However that should be a
                              > >miniscul minority of the surfing crowd.[/color]
                              >
                              > No, it's the majority, in fact you probably won't find a UA which
                              > tells the truth... Of course they might do somewhere in the string
                              > aswell as the lies, but then you're relying on the strength of your
                              > measuring script, I've yet to see a good one. Also of course people
                              > reaching your webserver has little to do with people viewing your
                              > site, and then there's the self-fulfilling aspect of logs. Could you
                              > explain why you believe the logs are "more and less accurate" ?[/color]

                              I scan logs with ANALOG which is a well known analyser that interprets
                              Apache logs. I believe Apache logs are more or less accurate because I
                              believe that for 5 years or so. Considering the general main stream
                              information about Apache logs, I do not see many reasons to doubt.

                              Now I need to go back to work guys!

                              was a nice discussion, thanks
                              Bart

                              Comment

                              Working...