Validation Question

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

    #1

    Validation Question


    I have an application that uses token values in HTML. The token values
    either feed or display data from a database linked with an ISAPI
    application. I have reached a point where I need to evaluate what the
    user enters into a quantity ordered field and compare it with the
    minimum quantity field. I created a variable for my min qty field:
    Var MinQty = “~~ML_UDF_MinQt yToken$~~”;

    The quantity entry box is set up like this:

    <td class="psdata" valign="top" align="left"><n obr><input
    type="~~mi_qty_ fld$~~" name="~~row_qua ntity_name$~~"
    value="~~quanti ty$~~" size="4" maxlength="10" class="formentr y">
    &nbsp;</nobr></td>

    How would I evaluate the value entered in the quantity box so it’s
    always grater than the min qty value? I would like to throw up a message
    box for the user when min qty is violated. Help appreciated. Thanks.
    Frank



    *** Sent via Developersdex http://www.developersdex.com ***
    Don't just participate in USENET...get rewarded for it!
  • Thomas 'PointedEars' Lahn

    #2
    Re: Validation Question

    Frank Py wrote:
    [color=blue]
    > Var MinQty = “~~ML_UDF_MinQt yToken$~~”;[/color]
    ^^^ ^^^^^^ ^ ^
    [1] [2] [3] [3]

    [1] The keyword is `var'. JavaScript is case-sensitive.

    [2] Identifiers starting with uppercase letters should
    be reserved for constructor function identifiers
    to avoid confusion. Instead, the first character
    of the identifier should be used as a prefix to
    indicate which type is expected.

    [3] You need to use straight single or double quotes as
    JavaScript string delimiters, not graphic ones. (Use
    a plain text editor, *not* a word processor.)
    And MinQty is a number, is it not? So its value
    should not be quoted at all, being a numeric literal.
    [color=blue]
    > The quantity entry box is set up like this:
    >
    > <td class="psdata" valign="top" align="left"><n obr><input
    > type="~~mi_qty_ fld$~~" name="~~row_qua ntity_name$~~"
    > value="~~quanti ty$~~" size="4" maxlength="10" class="formentr y">
    > &nbsp;</nobr></td>[/color]

    You know that this is invalid HTML, so it can only be the server-side
    code to be replaced before served, not what the user agent gets.
    [color=blue]
    > How would I evaluate the value entered in the quantity box so it’s
    > always grater than the min qty value? I would like to throw up a
    > message box for the user when min qty is violated.[/color]

    Now we are talking about client-side scripting, so you should have
    posted what the client (user agent) gets. You have not, so here is
    only *my* quick-hacked example which also avoids global variables:

    function checkValue(o)
    {
    var sMinQty = o.form.elements['qty_min'].value;
    if (+o.value < +sMinQty)
    {
    if (typeof prompt == "function" || typeof prompt == "object")
    {
    while (+o.value < +sMinQty)
    {
    o.value =
    prompt(
    "Below minimum quantity (" + sMinQty + ")."
    + " Type new value, or cancel to use the minimum.")
    || sMinQty;
    }
    }

    if (typeof o.focus == "function" || typeof o.focus == "object")
    o.focus();

    return false;
    }
    return true;
    }

    <form action="foobar" >
    <input type="hidden" name="qty_min" value="42">
    <input name="qty" onchange="check Value(this);">
    <input type="submit">
    </form>

    You could test for valid values on submit as well, and you have to do
    it always server-side since client-side scripting can be restricted,
    disabled or not even supported.

    <form
    action="foobar"
    onsubmit="retur n checkValue(this .elements['qty']);">
    <input type="hidden" name="qty_min" value="42">
    <input name="qty">
    <input type="submit">
    </form>


    HTH

    PointedEars

    Comment

    • Lasse Reichstein Nielsen

      #3
      Re: Validation Question

      Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:

      ....[color=blue]
      > Instead, the first character of the identifier should be used as a
      > prefix to indicate which type is expected.[/color]

      That is a matter of opinion, where I happen to hold a different one.

      While you *can* use the variable name to suggest the type of values
      you intent to let it refer to, I find that a good, descriptive name
      is sufficient. It is the only naming method that can be shown to
      other readers without further explanation.

      Otherwise I agree.
      /L
      --
      Lasse Reichstein Nielsen - lrn@hotpop.com
      DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
      'Faith without judgement merely degrades the spirit divine.'

      Comment

      • Laurent Bugnion, GalaSoft

        #4
        Re: Validation Question

        Hi,

        Lasse Reichstein Nielsen wrote:
        [color=blue]
        > Thomas 'PointedEars' Lahn <PointedEars@we b.de> writes:
        >
        > ...
        >[color=green]
        >>Instead, the first character of the identifier should be used as a
        >>prefix to indicate which type is expected.[/color]
        >
        >
        > That is a matter of opinion, where I happen to hold a different one.
        >
        > While you *can* use the variable name to suggest the type of values
        > you intent to let it refer to, I find that a good, descriptive name
        > is sufficient. It is the only naming method that can be shown to
        > other readers without further explanation.
        >
        > Otherwise I agree.
        > /L[/color]

        While I personally favour the Ungarish notation for identifiers (if only
        because it helps to find a variable faster when you use an Intellisense
        IDE like Visual Studio.NET), it should be noted that Microsoft
        recommends abandoning the Ungarish notation. The reasons given is:
        1) It makes the code language dependant, because not every language has
        the same type (or at least not the same type names). I think that this
        can be overcome by simply standardizing the prefixes for the set of
        languages one uses.
        2) It makes maintaining the code more difficult, because if you change
        the type of an identifier while developing or maintaining the code, you
        must also change the identifier name. I don't think it's such a big
        problem because the interface methods should not be modified anyway (or
        else programs using your code won't be compatible anymore), and for
        private code, you can use search and replace to facilitate the operation.

        We (my firm and project team) are currently talking quite a lot about
        this issue because we are setting up guidelines for our next project (in
        C#), and my opinion is that we will follow Microsoft's recommendation
        and abandon the Ungarish notation. I regret this, but it seems to be the
        trend nowadays.

        HTH,

        Laurent
        --
        Laurent Bugnion, GalaSoft
        Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
        Private/Malaysia: http://mypage.bluewin.ch/lbugnion
        Support children in Calcutta: http://www.calcutta-espoir.ch

        Comment

        • Thomas 'PointedEars' Lahn

          #5
          Re: Validation Question

          Laurent Bugnion wrote:
          [color=blue]
          > While I personally favour the Ungarish notation for identifiers (if only
          > because it helps to find a variable faster when you use an Intellisense
          > IDE like Visual Studio.NET), it should be noted that Microsoft
          > recommends abandoning the Ungarish notation. The reasons given is:
          > 1) It makes the code language dependant, because not every language has
          > the same type (or at least not the same type names). I think that this
          > can be overcome by simply standardizing the prefixes for the set of
          > languages one uses.
          > 2) It makes maintaining the code more difficult, because if you change
          > the type of an identifier while developing or maintaining the code, you
          > must also change the identifier name. I don't think it's such a big
          > problem because the interface methods should not be modified anyway (or
          > else programs using your code won't be compatible anymore), and for
          > private code, you can use search and replace to facilitate the operation.
          >
          > We (my firm and project team) are currently talking quite a lot about
          > this issue because we are setting up guidelines for our next project (in
          > C#), and my opinion is that we will follow Microsoft's recommendation
          > and abandon the Ungarish notation. I regret this, but it seems to be the
          > trend nowadays.[/color]

          Reading this through again at again, I cannot resolve the major issue:
          First you tell us that you favour the Ungarish notation and while
          citing what Microsoft recommends you successfully disprove these
          recommendations . But finally you tell us that it is your *opinion*
          to follow exactly the recommendations you have just disproved and
          at the same time you regret that. Now where is the logic in that?


          PointedEars

          P.S.
          I don't think you should use the name of your company in the From
          header, unless you post in their name or cannot change that.

          Comment

          • Laurent Bugnion, GalaSoft

            #6
            Re: Validation Question

            Hi,

            Thomas 'PointedEars' Lahn wrote:[color=blue]
            > Laurent Bugnion wrote:
            >
            >[color=green]
            >>While I personally favour the Ungarish notation for identifiers (if only
            >>because it helps to find a variable faster when you use an Intellisense
            >>IDE like Visual Studio.NET), it should be noted that Microsoft
            >>recommends abandoning the Ungarish notation. The reasons given is:
            >>1) It makes the code language dependant, because not every language has
            >>the same type (or at least not the same type names). I think that this
            >>can be overcome by simply standardizing the prefixes for the set of
            >>languages one uses.
            >>2) It makes maintaining the code more difficult, because if you change
            >>the type of an identifier while developing or maintaining the code, you
            >>must also change the identifier name. I don't think it's such a big
            >>problem because the interface methods should not be modified anyway (or
            >>else programs using your code won't be compatible anymore), and for
            >>private code, you can use search and replace to facilitate the operation.
            >>
            >>We (my firm and project team) are currently talking quite a lot about
            >>this issue because we are setting up guidelines for our next project (in
            >>C#), and my opinion is that we will follow Microsoft's recommendation
            >>and abandon the Ungarish notation. I regret this, but it seems to be the
            >>trend nowadays.[/color]
            >
            >
            > Reading this through again at again, I cannot resolve the major issue:
            > First you tell us that you favour the Ungarish notation and while
            > citing what Microsoft recommends you successfully disprove these
            > recommendations . But finally you tell us that it is your *opinion*
            > to follow exactly the recommendations you have just disproved and
            > at the same time you regret that. Now where is the logic in that?[/color]

            I said that my opinion is that we *will* follow Microsoft's
            recommendation. I also said that I regret that this is what we will do,
            because I favour ungarish notation. I don't see a contradiction in that.
            When you're in a team, you follow the team's decisions even if you would
            prefer to do something else.
            [color=blue]
            > PointedEars
            >
            > P.S.
            > I don't think you should use the name of your company in the From
            > header, unless you post in their name or cannot change that.[/color]

            Well, my firm is Siemens Building Technologies, and I didn't post in
            their name (though I would if I wanted to). GalaSoft is just a hobby.
            GalaSoft is me. I post in my name.

            Besides, how is that your problem anyway?

            Laurent
            --
            Laurent Bugnion, GalaSoft
            Webdesign, Java, JavaScript: http://www.galasoft-LB.ch
            Private/Malaysia: http://mypage.bluewin.ch/lbugnion
            Support children in Calcutta: http://www.calcutta-espoir.ch

            Comment

            • Jim Ley

              #7
              Re: Validation Question

              On Mon, 29 Dec 2003 11:12:44 +0100, "Laurent Bugnion, GalaSoft"
              <galasoft-LB@bluewin_NO_S PAM.ch> wrote:
              [color=blue]
              >While I personally favour the Ungarish notation for identifiers (if only
              >because it helps to find a variable faster when you use an Intellisense
              >IDE like Visual Studio.NET),[/color]

              Really? I find it harder to find as everything begins with the same
              f'in character!
              [color=blue]
              > it should be noted that Microsoft
              >recommends abandoning the Ungarish notation.[/color]

              So that's why I've seen it going out of favour, I'm pleased, in IDE's
              they'll generally tell you the type anyway.

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

              Comment

              • Laurent Bugnion, GalaSoft

                #8
                Re: Validation Question

                Hi Jim,

                Jim Ley wrote:
                [color=blue]
                > On Mon, 29 Dec 2003 11:12:44 +0100, "Laurent Bugnion, GalaSoft"
                > <galasoft-LB@bluewin_NO_S PAM.ch> wrote:
                >
                >[color=green]
                >>While I personally favour the Ungarish notation for identifiers (if only
                >>because it helps to find a variable faster when you use an Intellisense
                >>IDE like Visual Studio.NET),[/color]
                >
                >
                > Really? I find it harder to find as everything begins with the same
                > f'in character![/color]

                I am well aware that ungarish notation is much of a personal taste. Some
                hate it and some love it. Me, I am moderate usually and I like it ;-)

                In general, when I look for an identifier in Intellisense, my first
                question is "what type does it have" before I ask myself "how is it
                named?". That's why ungarish notation rather helps me to find things
                faster. That said, I can also live without it.

                [color=blue][color=green]
                >>it should be noted that Microsoft
                >>recommends abandoning the Ungarish notation.[/color]
                >
                >
                > So that's why I've seen it going out of favour, I'm pleased, in IDE's
                > they'll generally tell you the type anyway.
                >
                > Jim.[/color]

                True, but the identifiers aren't grouped according to the type.

                Regards,

                Laurent
                --
                Laurent Bugnion, GalaSoft
                Software engineering: http://www.galasoft-LB.ch
                Private/Malaysia: http://mypage.bluewin.ch/lbugnion
                Support children in Calcutta: http://www.calcutta-espoir.ch

                Comment

                • Frank Py

                  #9
                  Re: Validation Question

                  Thanks for all the examples.

                  Sincerely,
                  Frank



                  *** Sent via Developersdex http://www.developersdex.com ***
                  Don't just participate in USENET...get rewarded for it!

                  Comment

                  • Thomas 'PointedEars' Lahn

                    #10
                    Re: Validation Question

                    Laurent Bugnion, GalaSoft wrote:
                    [color=blue]
                    > Thomas 'PointedEars' Lahn wrote:[color=green]
                    >> [...]
                    >> First you tell us that you favour the Ungarish notation and while
                    >> citing what Microsoft recommends you successfully disprove these
                    >> recommendations . But finally you tell us that it is your *opinion*
                    >> to follow exactly the recommendations you have just disproved and
                    >> at the same time you regret that. Now where is the logic in that?[/color]
                    >
                    > I said that my opinion is that we *will* follow Microsoft's
                    > recommendation. I also said that I regret that this is what we will do,
                    > because I favour ungarish notation. I don't see a contradiction in that.
                    > When you're in a team, you follow the team's decisions even if you would
                    > prefer to do something else.[/color]

                    I understand now that you most certainly meant `opinion' as `outlook'.
                    I knew the word only in the meaning of `attitude' previously.
                    [color=blue][color=green]
                    >> P.S.
                    >> I don't think you should use the name of your company in the From
                    >> header, unless you post in their name or cannot change that.[/color]
                    >
                    > Well, my firm is Siemens Building Technologies, and I didn't post in
                    > their name (though I would if I wanted to). GalaSoft is just a hobby.
                    > GalaSoft is me. I post in my name.[/color]

                    ACK
                    [color=blue]
                    > Besides, how is that your problem anyway?[/color]

                    If that would be the name of your company, it could get you in
                    trouble if not intended by the company. Otherwise it could get
                    you in trouble, too, posting private at work. Now as it is
                    only a hobby, it may look like posing yourselves. You may have
                    noted that you happen to be one of the few posters here to use
                    a company name in the From header.

                    But since I note that your From address is none, it happens to
                    become your problem alone as I will not read your articles anymore.

                    [en] <http://www.interhack.n et/pubs/munging-harmful/>
                    [de] <http://www.gerlo.de/falsche-email-adressen.html>


                    HTH & HAND

                    PointedEars

                    Comment

                    • Laurent Bugnion, GalaSoft

                      #11
                      Re: Validation Question

                      Hi,

                      Thomas 'PointedEars' Lahn wrote:

                      <snip>
                      [color=blue]
                      > If that would be the name of your company, it could get you in
                      > trouble if not intended by the company. Otherwise it could get
                      > you in trouble, too, posting private at work. Now as it is
                      > only a hobby, it may look like posing yourselves. You may have
                      > noted that you happen to be one of the few posters here to use
                      > a company name in the From header.[/color]

                      Yes, I do this for years (literally), and I notice that you're the first
                      one to ever comment about it. Which brings me back to my original
                      comment: Why is that even your problem? It's comp.lang.javas cript here,
                      not comp.lang.i.giv e.advices.about .everything
                      [color=blue]
                      > But since I note that your From address is none, it happens to
                      > become your problem alone as I will not read your articles anymore.[/color]

                      Good riddance.
                      [color=blue]
                      > [en] <http://www.interhack.n et/pubs/munging-harmful/>
                      > [de] <http://www.gerlo.de/falsche-email-adressen.html>[/color]

                      I read that before you even started posting here. My opinion (means:
                      What I believe) is that it's bullshit. The internet has other, much more
                      serious problems to fear. One of those is people posting tons of
                      offtopic messages to programming newsgroups to appear knowledgeable.
                      [color=blue]
                      > HTH & HAND
                      >
                      > PointedEars[/color]

                      Whatever,

                      Laurent
                      --
                      Laurent Bugnion, GalaSoft
                      Software engineering: http://www.galasoft-LB.ch
                      Private/Malaysia: http://mypage.bluewin.ch/lbugnion
                      Support children in Calcutta: http://www.calcutta-espoir.ch

                      Comment

                      • Dr John Stockton

                        #12
                        Re: Validation Question

                        JRS: In article <3FF31CF7.80909 05@PointedEars. de>, seen in
                        news:comp.lang. javascript, Thomas 'PointedEars' Lahn
                        <PointedEars@we b.de> posted at Wed, 31 Dec 2003 20:01:11 :-[color=blue]
                        >
                        >But since I note that your From address is none, it happens to
                        >become your problem alone as I will not read your articles anymore.[/color]

                        Have you considered using the services of a psychiatrist?

                        --
                        © John Stockton, Surrey, UK. ???@merlyn.demo n.co.uk Turnpike v4.00 MIME. ©
                        Web <URL:http://www.merlyn.demo n.co.uk/> - FAQish topics, acronyms, & links.
                        Check boilerplate spelling -- error is a public sign of incompetence.
                        Never fully trust an article from a poster who gives no full real name.

                        Comment

                        Working...