Javascript - ASP

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

    Javascript - ASP

    I have a page written in ASP and I added some Javascript code to
    ensure the input boxes are filled with correct data. That check is
    performed every time the user moves out from a textbox. Now right
    before I submit the form to the server for processing, I want to make
    a final test on the values.

    <input type="submit" onClick="testRe sults(this.form )" value="Submit" >

    The problem here is that I make the check in the testResults function
    and popup an alert, but still the page goes in the server for
    processing. How to make it like when there is problem after click
    submit to popup an alert and not send the page for processing.

    Thanks
    Marios Koumides
  • Erwin Moller

    #2
    Re: Javascript - ASP

    Marios Koumides wrote:
    [color=blue]
    > I have a page written in ASP and I added some Javascript code to
    > ensure the input boxes are filled with correct data. That check is
    > performed every time the user moves out from a textbox. Now right
    > before I submit the form to the server for processing, I want to make
    > a final test on the values.
    >
    > <input type="submit" onClick="testRe sults(this.form )" value="Submit" >
    >
    > The problem here is that I make the check in the testResults function
    > and popup an alert, but still the page goes in the server for
    > processing. How to make it like when there is problem after click
    > submit to popup an alert and not send the page for processing.
    >
    > Thanks
    > Marios Koumides[/color]

    Hi,

    2 solutions.

    first: Make it a button.
    <input type="button" onClick="testRe sults(this.form )" value="Submit" >

    now use your function testResults to submit the form.
    something like:
    document.forms["formnamehe re"].submit();

    Second:
    use onSubmit instead for onClick.
    return false to prevent submitting.

    I prefer the first, but that is a matter of taste.
    The second approach has the advantage to work if client doesn't have JS
    enabled.
    But that is also the disadvantage: no checking...
    That is why I prefer the first.
    (Who doesn't have JS anyway except some companies with bad admins who forbid
    anything they don't understand.)

    Hope that helps.

    Regards,
    Erwin Moller

    Comment

    • koumides@gmail.com

      #3
      Re: Javascript - ASP

      Thanks a lot mate ! You couldn't be more helpful.

      Comment

      • RobB

        #4
        Re: Javascript - ASP

        Erwin Moller wrote:[color=blue]
        > Marios Koumides wrote:
        >[color=green]
        > > I have a page written in ASP and I added some Javascript code to
        > > ensure the input boxes are filled with correct data. That check is
        > > performed every time the user moves out from a textbox. Now right
        > > before I submit the form to the server for processing, I want to[/color][/color]
        make[color=blue][color=green]
        > > a final test on the values.
        > >
        > > <input type="submit" onClick="testRe sults(this.form )"[/color][/color]
        value="Submit" >[color=blue][color=green]
        > >
        > > The problem here is that I make the check in the testResults[/color][/color]
        function[color=blue][color=green]
        > > and popup an alert, but still the page goes in the server for
        > > processing. How to make it like when there is problem after click
        > > submit to popup an alert and not send the page for processing.
        > >
        > > Thanks
        > > Marios Koumides[/color]
        >
        > Hi,
        >
        > 2 solutions.
        >
        > first: Make it a button.
        > <input type="button" onClick="testRe sults(this.form )" value="Submit"
        >
        >
        > now use your function testResults to submit the form.
        > something like:
        > document.forms["formnamehe re"].submit();
        >
        > Second:
        > use onSubmit instead for onClick.
        > return false to prevent submitting.
        >
        > I prefer the first, but that is a matter of taste.
        > The second approach has the advantage to work if client doesn't have[/color]
        JS[color=blue]
        > enabled.
        > But that is also the disadvantage: no checking...[/color]

        No checking...of what?
        [color=blue]
        > That is why I prefer the first.[/color]

        The proper way to validate is via the form's onsubmit handler. The only
        reason to call Form.submit() explicitly is because of special form
        handling that can't be done any other way.
        [color=blue]
        > (Who doesn't have JS anyway except some companies with bad admins who[/color]
        forbid[color=blue]
        > anything they don't understand.)
        >[/color]

        Plenty of people, sorry. Why lose them unnecessarily?

        Comment

        • Erwin Moller

          #5
          Re: Javascript - ASP

          RobB wrote:
          [color=blue]
          > Erwin Moller wrote:[color=green]
          >> Marios Koumides wrote:
          >>[color=darkred]
          >> > I have a page written in ASP and I added some Javascript code to
          >> > ensure the input boxes are filled with correct data. That check is
          >> > performed every time the user moves out from a textbox. Now right
          >> > before I submit the form to the server for processing, I want to[/color][/color]
          > make[color=green][color=darkred]
          >> > a final test on the values.
          >> >
          >> > <input type="submit" onClick="testRe sults(this.form )"[/color][/color]
          > value="Submit" >[color=green][color=darkred]
          >> >
          >> > The problem here is that I make the check in the testResults[/color][/color]
          > function[color=green][color=darkred]
          >> > and popup an alert, but still the page goes in the server for
          >> > processing. How to make it like when there is problem after click
          >> > submit to popup an alert and not send the page for processing.
          >> >
          >> > Thanks
          >> > Marios Koumides[/color]
          >>
          >> Hi,
          >>
          >> 2 solutions.
          >>
          >> first: Make it a button.
          >> <input type="button" onClick="testRe sults(this.form )" value="Submit"
          >>
          >>
          >> now use your function testResults to submit the form.
          >> something like:
          >> document.forms["formnamehe re"].submit();
          >>
          >> Second:
          >> use onSubmit instead for onClick.
          >> return false to prevent submitting.
          >>
          >> I prefer the first, but that is a matter of taste.
          >> The second approach has the advantage to work if client doesn't have[/color]
          > JS[color=green]
          >> enabled.
          >> But that is also the disadvantage: no checking...[/color]
          >
          > No checking...of what?[/color]

          Checking of what?
          Of the inputfields of course, clientside, before submitting.
          What else?
          This is what we are talking about.

          [color=blue]
          >[color=green]
          >> That is why I prefer the first.[/color]
          >
          > The proper way to validate is via the form's onsubmit handler. The only
          > reason to call Form.submit() explicitly is because of special form
          > handling that can't be done any other way.[/color]

          That is one opinion.

          I have another.

          I use a lot JS, also for required functionality. (So the site doesn't work
          without it.)
          For me it is like saying: "You need Flash to see this Flash-movie."

          If people don't want JS enabled, so be it.
          I don't mind loosing them.

          I never had a customer demanding that I made an application that runs
          without JS.
          I TRY to avoid it, but if I need JS, I just use it.
          [color=blue]
          >[color=green]
          >> (Who doesn't have JS anyway except some companies with bad admins who[/color]
          > forbid[color=green]
          >> anything they don't understand.)
          >>[/color]
          >
          > Plenty of people, sorry. Why lose them unnecessarily?[/color]

          All browsers I have seen the last few years (in a lot of places) had JS
          enabled.
          I know there are people that don't have it enabled or cannot enable it, but
          only of hearsay. :-)

          Regards,
          Erwin Moller


          Comment

          • RobB

            #6
            Re: Javascript - ASP

            Erwin Moller wrote:[color=blue]
            > RobB wrote:
            >[color=green]
            > > Erwin Moller wrote:[color=darkred]
            > >> Marios Koumides wrote:
            > >>
            > >> > I have a page written in ASP and I added some Javascript code to
            > >> > ensure the input boxes are filled with correct data. That check[/color][/color][/color]
            is[color=blue][color=green][color=darkred]
            > >> > performed every time the user moves out from a textbox. Now[/color][/color][/color]
            right[color=blue][color=green][color=darkred]
            > >> > before I submit the form to the server for processing, I want to[/color]
            > > make[color=darkred]
            > >> > a final test on the values.
            > >> >
            > >> > <input type="submit" onClick="testRe sults(this.form )"[/color]
            > > value="Submit" >[color=darkred]
            > >> >
            > >> > The problem here is that I make the check in the testResults[/color]
            > > function[color=darkred]
            > >> > and popup an alert, but still the page goes in the server for
            > >> > processing. How to make it like when there is problem after[/color][/color][/color]
            click[color=blue][color=green][color=darkred]
            > >> > submit to popup an alert and not send the page for processing.
            > >> >
            > >> > Thanks
            > >> > Marios Koumides
            > >>
            > >> Hi,
            > >>
            > >> 2 solutions.
            > >>
            > >> first: Make it a button.
            > >> <input type="button" onClick="testRe sults(this.form )"[/color][/color][/color]
            value="Submit"[color=blue][color=green][color=darkred]
            > >>
            > >>
            > >> now use your function testResults to submit the form.
            > >> something like:
            > >> document.forms["formnamehe re"].submit();
            > >>
            > >> Second:
            > >> use onSubmit instead for onClick.
            > >> return false to prevent submitting.
            > >>
            > >> I prefer the first, but that is a matter of taste.
            > >> The second approach has the advantage to work if client doesn't[/color][/color][/color]
            have[color=blue][color=green]
            > > JS[color=darkred]
            > >> enabled.
            > >> But that is also the disadvantage: no checking...[/color]
            > >
            > > No checking...of what?[/color]
            >
            > Checking of what?
            > Of the inputfields of course, clientside, before submitting.
            > What else?
            > This is what we are talking about.
            >
            >[color=green]
            > >[color=darkred]
            > >> That is why I prefer the first.[/color]
            > >
            > > The proper way to validate is via the form's onsubmit handler. The[/color][/color]
            only[color=blue][color=green]
            > > reason to call Form.submit() explicitly is because of special form
            > > handling that can't be done any other way.[/color]
            >
            > That is one opinion.
            >
            > I have another.
            >
            > I use a lot JS, also for required functionality. (So the site doesn't[/color]
            work[color=blue]
            > without it.)
            > For me it is like saying: "You need Flash to see this Flash-movie."
            >
            > If people don't want JS enabled, so be it.
            > I don't mind loosing them.
            >
            > I never had a customer demanding that I made an application that runs[/color]
            [color=blue]
            > without JS.
            > I TRY to avoid it, but if I need JS, I just use it.
            >[color=green]
            > >[color=darkred]
            > >> (Who doesn't have JS anyway except some companies with bad admins[/color][/color][/color]
            who[color=blue][color=green]
            > > forbid[color=darkred]
            > >> anything they don't understand.)
            > >>[/color]
            > >
            > > Plenty of people, sorry. Why lose them unnecessarily?[/color]
            >
            > All browsers I have seen the last few years (in a lot of places) had[/color]
            JS[color=blue]
            > enabled.
            > I know there are people that don't have it enabled or cannot enable[/color]
            it, but[color=blue]
            > only of hearsay. :-)
            >
            > Regards,
            > Erwin Moller[/color]

            Hi Erwin.

            Respectfully - I understand your situation, but this is usenet, and
            posters (including the OP) may have different requirements. If you only
            used Internet Explorer in your work environment, would it be therefore
            unnecessary to bother making your posts here functional cross-browser?
            These aren't customers (more's the pity !) and they may be less
            sanguine about losing users unnecessarily. And 'unnecessarily' is the
            key word here, as you still haven't explained the comment that caught
            my attention:
            [color=blue][color=green][color=darkred]
            > >> The second approach has the advantage to work if client doesn't[/color][/color][/color]
            have[color=blue][color=green]
            > > JS[color=darkred]
            > >> enabled.
            > >> But that is also the disadvantage: no checking...[/color][/color][/color]

            Then you check at the server, which you should be doing anyway. How is
            losing the user/customer entirely preferable?

            Comment

            • Erwin Moller

              #7
              Re: Javascript - ASP

              RobB wrote:

              <snip>

              Hi Rob,
              [color=blue]
              >
              > Hi Erwin.
              >
              > Respectfully - I understand your situation, but this is usenet, and
              > posters (including the OP) may have different requirements. If you only
              > used Internet Explorer in your work environment, would it be therefore
              > unnecessary to bother making your posts here functional cross-browser?[/color]

              Well of course not.
              I always work crossbrowser.
              And I always try to avoid JS for real functionality, but it just isn't
              possible in all situations.

              [color=blue]
              > These aren't customers (more's the pity !) and they may be less
              > sanguine about losing users unnecessarily.[/color]

              I agree with you Rob.
              Read on:

              And 'unnecessarily' is the[color=blue]
              > key word here, as you still haven't explained the comment that caught
              > my attention:
              >[color=green][color=darkred]
              >> >> The second approach has the advantage to work if client doesn't[/color][/color]
              > have[color=green][color=darkred]
              >> > JS
              >> >> enabled.
              >> >> But that is also the disadvantage: no checking...[/color][/color][/color]

              I was saying here that the onSubmit()-approach will have the advantage that
              the form will submit regardless of the fact if JS is working.
              That is the advantage.
              The disadvantage: No checking is done clientside.

              So if you really want to do some checks: demand JS.

              That is all I wanted to say.

              Maybe I said it a little rude and unclear. Sorry for that.

              [color=blue]
              >
              > Then you check at the server, which you should be doing anyway. How is
              > losing the user/customer entirely preferable?[/color]

              Is that preferable?
              Nope.
              As I wrote in my original piece: If you can avoid demanding JS, do so.

              I was merely making a case for the fact that certain requirements can lead
              to demands on the client. Like Flashmovies demand Flash installed.
              If you want to do clientside checking: demand JS.

              In that context (demanding JS) I don't see much difference between
              from.submit() and the onSubmit approach.

              I don't think we disagree that much. :-)

              Regards,
              Erwin Moller

              Comment

              Working...