Form or Javascript Problem

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Dennis M. Marks

    #1

    Form or Javascript Problem

    On my web site, indicated below, go to the yearly calendar page. Upon
    entry it shows the current year. The arrows at the top make it go
    forward and backward. If you put a date into the little box and click
    outside the box it creates that year. If you put a date in the box and
    press return the calendar is drawn and then the page immediately
    reloads. Why?

    --
    Dennis M. Marks

    Replace domain.invalid with dcsi.net


    -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
    http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
    -----== Over 100,000 Newsgroups - 19 Different Servers! =-----
  • mscir

    #2
    Re: Form or Javascript Problem

    Dennis M. Marks wrote:
    [color=blue]
    > On my web site, indicated below, go to the yearly calendar page. Upon
    > entry it shows the current year. The arrows at the top make it go
    > forward and backward. If you put a date into the little box and click
    > outside the box it creates that year. If you put a date in the box and
    > press return the calendar is drawn and then the page immediately
    > reloads. Why?[/color]

    I believe this is standard behavior when you have only one text box in a
    form, a return acts like a form submit.

    If you add a second textbox (including hidden textboxes) I believe this
    will stop happening, but the calendars won't redraw when you hit return
    in the first text box anymore. You might add a button next to the text
    box to call the function if you use this approach, or watch for the
    return keypress in the textbox.

    <input type="text" value="test0" style="visibili ty:hidden;">

    Mike

    Comment

    • Fox

      #3
      Re: Form or Javascript Problem



      "Dennis M. Marks" wrote:[color=blue]
      >
      > On my web site, indicated below, go to the yearly calendar page. Upon
      > entry it shows the current year. The arrows at the top make it go
      > forward and backward. If you put a date into the little box and click
      > outside the box it creates that year. If you put a date in the box and
      > press return the calendar is drawn and then the page immediately
      > reloads. Why?[/color]

      forms automatically "submit" when the user types Enter (if focus is in a
      form field), unless directed otherwise.

      try:

      <form onsubmit = "return false">

      it's better to have the form respond to the user typing return, so your
      form should call the createCalendar routine onsubmit. You will still
      need to "return false" either from the function itself, or as a second
      statement to the onsubmit property:

      <form onsubmit = "createCalendar (arglist); return false"> or have
      createCalendar( ..) { ... return false; } and <form onsubmit = "return createCalendar( arglist)">

      Fox
      *************** **

      [color=blue]
      >
      > --
      > Dennis M. Marks
      > http://www.dcs-chico.com/~denmarks/
      > Replace domain.invalid with dcsi.net
      >
      > -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
      > http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
      > -----== Over 100,000 Newsgroups - 19 Different Servers! =-----[/color]

      Comment

      • Michael Winter

        #4
        Re: Form or Javascript Problem

        On Sun, 18 Apr 2004 19:56:01 -0700, Dennis M. Marks
        <denmarks@domai n.invalid> wrote:
        [color=blue]
        > On my web site, indicated below, go to the yearly calendar page. Upon
        > entry it shows the current year. The arrows at the top make it go
        > forward and backward. If you put a date into the little box and click
        > outside the box it creates that year. If you put a date in the box and
        > press return the calendar is drawn and then the page immediately
        > reloads. Why?[/color]

        The others have indicated why, but have given unnecessarily complicated
        solutions. Simply remove the FORM element. You don't use it, and it's
        invalid mark-up, too. FORM elements are only required to submit values[1],
        not to contain form controls.

        Mike


        [1] You could also use them for ease of reference, rather than relying on
        getElementById( ), and the like.

        --
        Michael Winter
        M.Winter@blueyo nder.co.invalid (replace ".invalid" with ".uk" to reply)

        Comment

        • Dennis M. Marks

          #5
          Re: Form or Javascript Problem

          In article <opr6pm7wn65vkl cq@news-text.blueyonder .co.uk>, Michael
          Winter <M.Winter@bluey onder.co.invali d> wrote:
          [color=blue]
          > On Sun, 18 Apr 2004 19:56:01 -0700, Dennis M. Marks
          > <denmarks@domai n.invalid> wrote:
          >[color=green]
          > > On my web site, indicated below, go to the yearly calendar page. Upon
          > > entry it shows the current year. The arrows at the top make it go
          > > forward and backward. If you put a date into the little box and click
          > > outside the box it creates that year. If you put a date in the box and
          > > press return the calendar is drawn and then the page immediately
          > > reloads. Why?[/color]
          >
          > The others have indicated why, but have given unnecessarily complicated
          > solutions. Simply remove the FORM element. You don't use it, and it's
          > invalid mark-up, too. FORM elements are only required to submit values[1],
          > not to contain form controls.
          >
          > Mike
          >
          >
          > [1] You could also use them for ease of reference, rather than relying on
          > getElementById( ), and the like.[/color]

          Thanks for all the advice. The best method was as follows:

          <form onsubmit="retur n false">
          Enter year and click create <input type="text" size="5" maxlength="4"
          onchange="y=thi s.value; initPage()" />
          <input type="submit" value="create"/ >
          </form>

          The submit button doesn't really do anything but it gives a place to
          click outside the box.

          --
          Dennis M. Marks

          Replace domain.invalid with dcsi.net


          -----= Posted via Newsfeeds.Com, Uncensored Usenet News =-----
          http://www.newsfeeds.com - The #1 Newsgroup Service in the World!
          -----== Over 100,000 Newsgroups - 19 Different Servers! =-----

          Comment

          Working...