Form Question

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

    #1

    Form Question

    I use forms where City and State names have to be entered, entry's that
    have two names (example: New York) must have a lower dash inserted in
    them
    (example: New_York) before the form can be submitted, is there a way
    this can be done with an onBlur event handler?
    Thanks for any help, Joe

  • Lee

    #2
    Re: Form Question

    Papajo said:[color=blue]
    >
    > I use forms where City and State names have to be entered, entry's that
    >have two names (example: New York) must have a lower dash inserted in
    >them
    >(example: New_York) before the form can be submitted, is there a way
    >this can be done with an onBlur event handler?[/color]

    It could be done using an event handler, but chances are that some
    of your visitors will have Javascript disabled.

    The only reliable solution is to fix your server side code so that
    it doesn't matter.

    Comment

    • RobG

      #3
      Re: Form Question

      Papajo wrote:[color=blue]
      > I use forms where City and State names have to be entered, entry's that
      > have two names (example: New York) must have a lower dash inserted in
      > them
      > (example: New_York) before the form can be submitted, is there a way
      > this can be done with an onBlur event handler?
      > Thanks for any help, Joe
      >[/color]

      As Lee says, there's no way of ensuring that this actually runs
      before the form is submitted. But for the record, here's how to
      do it:

      <script type="text/javascript">
      function spaceToScore(t) {
      var oVal = t.value;
      var rexp = /^(\s+)?(.*\S)(\ s+)?$/;
      t.value = t.value.replace (rexp,'$2').rep lace(/\s+/g,'\_');
      alert('Orig: \'' + oVal + '\'\nNow : \'' + t.value + '\'');
      }
      </script>

      <form action="" onsubmit="
      return spaceToScore(th is.textInput);
      ">
      <input type="text" name="textInput " value=" asdf asdf ">
      <input type="submit">
      </form>


      --
      Rob

      Comment

      • micha

        #4
        Re: Form Question

        you could use onSubmit which is executed before sending the data.

        <form ... onSubmit="retur n lower_dash_func tion();">

        lower_dash_func tion does
        1. replace spaces in your input fields
        2. returns true to submit the form

        best way imho would probaly be to add the lower dash in the script that
        performs the form action though

        micha

        Comment

        Working...