help! user defined objects in a string...

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • grandeandy@gmail.com

    help! user defined objects in a string...

    I have been racking my brain out trying to get this to work... (I am
    new to javascript)...

    Below is what I am trying to accomplish. I want to have the areas with
    +txt+ to have the user defined variable inserted. I can't seem to get
    it to work.



    <html><head>
    <script type="text/javascript">
    function color(txt)
    {
    var check = document.formx. i+txt+.value;
    if (check=='') {
    d+txt+.style.ba ckground='#ffff ff';
    }
    else {
    d+txt+.style.ba ckground='#c0c0 c0';
    }
    }
    </script>
    </head><body>

    <div id="dv1">
    Name of vendor: <input type=text name=iv2 disabled
    onkeyup="color( v1)"><BR>
    </div>

    <div id="dv2">
    Name of agent: <input type=text name=iv2 disabled
    onkeyup="color( v2)"><BR>
    </div>

  • Richard Cornford

    #2
    Re: help! user defined objects in a string...

    grandeandy@gmai l.com wrote:[color=blue]
    > I have been racking my brain out trying to get this
    > to work... (I am new to javascript)...
    >
    > Below is what I am trying to accomplish. I want to
    > have the areas with +txt+ to have the user defined
    > variable inserted. I can't seem to get
    > it to work.[/color]
    <snip>[color=blue]
    > var check = document.formx. i+txt+.value;[/color]
    <snip>

    Look in the FAQ:-

    <URL: http://jibbering.com/faq/#FAQ4_39 >

    (<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >)

    Richard.


    Comment

    • grandeandy@gmail.com

      #3
      Re: help! user defined objects in a string...


      Richard Cornford wrote:[color=blue]
      > grandeandy@gmai l.com wrote:[color=green]
      > > I have been racking my brain out trying to get this
      > > to work... (I am new to javascript)...
      > >
      > > Below is what I am trying to accomplish. I want to
      > > have the areas with +txt+ to have the user defined
      > > variable inserted. I can't seem to get
      > > it to work.[/color]
      > <snip>[color=green]
      > > var check = document.formx. i+txt+.value;[/color]
      > <snip>
      >
      > Look in the FAQ:-
      >
      > <URL: http://jibbering.com/faq/#FAQ4_39 >
      >
      > (<URL: http://jibbering.com/faq/faq_notes/square_brackets.html >)
      >
      > Richard.[/color]


      Hmm... I tried it like the FAQ said, but still no luck. Would you mind
      posting a working version of the code I posted? It keeps saying object
      undefined.

      Comment

      • Michael Winter

        #4
        Re: help! user defined objects in a string...

        On 29/03/2005 22:18, grandeandy@gmai l.com wrote:

        [snip]
        [color=blue][color=green]
        >> <URL: http://jibbering.com/faq/faq_notes/square_brackets.html >[/color]
        >
        > Hmm... I tried it like the FAQ said, but still no luck.[/color]

        Presumably you haven't changed your function calls so that you're
        passing string literals not identifiers.

        onkeyup="color( v1)"

        The script engine will be trying to find - and failing, too - a
        variable named v1. Quote it with single quotes.
        [color=blue]
        > Would you mind posting a working version of the code I posted?[/color]

        An example might be in order as there are other issues.

        1) You seem to be trying to use the id attribute values of the
        two DIV elements as global variables. Don't. That's nonsense
        introduced by Microsoft that you'd do well to avoid.
        2) Disabling a form control in the mark-up itself is not
        something you should do in any environment where you cannot
        guarantee script support. Namely, the Web. If you're going to
        need a script to enable something, or show something, you
        should also use a script to disable or hide that thing in the
        first place.
        3) You can avoid worrying about the name or id attributes of
        elements by passing a reference to the function and using the
        DOM to access those element according to their structural
        relationship. The example below demonstrates this.

        It would seem that you're trying to colour around controls which have
        values. A nicer approach than using DIVs would be to use LABELs. If
        necessary, you can always make them block-level (using the a "display:
        block" declaration in your style sheet) if need be. Also, if you want
        some padding underneath the controls, use padding not a forced line break.

        function highlight(contr ol) {var colour, label;
        /* Control is a reference to the form control.
        * If its value is not an empty string, use a
        * light grey...
        */
        if(control.valu e) {colour = '#c0c0c0';}
        /* ...otherwise use white. */
        else {colour = '#ffffff';}

        /* If we can obtain a reference to the parent node (the
        * LABEL element), and that node has a style object...
        */
        if((label = control.parentN ode) && label.style) {
        /* ...set the background colour to the previously
        * determined colour.
        */
        label.style.bac kgroundColor = colour;
        }
        }


        <label>Name of vendor:
        <input type="text" name="iv1" onkeyup="highli ght(this);">
        </label>

        Hope that helps,
        Mike

        --
        Michael Winter
        Replace ".invalid" with ".uk" to reply by e-mail.

        Comment

        • Richard Cornford

          #5
          Re: help! user defined objects in a string...

          grandeandy@gmai l.com wrote:[color=blue]
          > Richard Cornford wrote:[color=green]
          >> grandeandy@gmai l.com wrote:[/color][/color]
          <snip>[color=blue][color=green][color=darkred]
          >>> ... . I want to
          >>> have the areas with +txt+ to have the user defined
          >>> variable inserted. I can't seem to get
          >>> it to work.[/color]
          >><snip>[color=darkred]
          >>> var check = document.formx. i+txt+.value;[/color]
          >><snip>
          >>
          >> Look in the FAQ:-
          >>
          >> <URL: http://jibbering.com/faq/#FAQ4_39 >[/color][/color]
          <snip>[color=blue]
          > Hmm... I tried it like the FAQ said, but still no luck.[/color]

          Luck is not a factor in computer programming.
          [color=blue]
          > Would you mind posting a working version of the code I
          > posted?[/color]
          [color=blue]
          > It keeps saying object undefined.[/color]

          That is very unlikely to be what it actually says. But it is in the
          nature of computers that specific conditions produce specific error
          messages. Those error messages may all seem vague and indistinct at
          first but we have seen enough of them to be able to deduce a great deal
          from them, given the _exact_ wording (and knowledge of the nature of the
          system producing those errors).

          That is not how it works. If I post complete code that does what you
          appear to want all that will happen is that you will come back looking
          for copulate code to solve your next problem. If, on the other hand, we
          promote an understanding of whatever you are doing wrong, or
          misunderstandin g, then you will be in a position to solve your own
          problems, and may eventually be in a position to provide assistance to
          others.

          If you have tried to implement a version of your code that uses
          appropriate bracket notation property accessors to allow the dynamic
          construction of property names and the result does not work then you
          have either erred, or misunderstood. What you now do is post that code
          and someone will (may[1]) tell you what you have done wrong, and/or
          attempt to explain and correct your misconception(s ).

          Richard.

          [1] It is impossible to guarantee that any post will get a response, and
          many shoot themselves in the foot by disregarding Usenet conventions or
          failing to fully read the FAQ before asking questions. Both can be
          avoided.


          Comment

          • grandeandy@gmail.com

            #6
            Re: help! user defined objects in a string...

            Thank you so much for your help! Actually seeing the code helped so
            much, because I was able to actually see what works, and use that
            information along with what I know about what doesn't work.

            Really appreciate it.

            Thanks to Richard as well for the words on education within the
            community.

            Comment

            • Lee

              #7
              Re: help! user defined objects in a string...

              Richard Cornford said:
              [color=blue]
              >That is not how it works. If I post complete code that does what you
              >appear to want all that will happen is that you will come back looking
              >for copulate code to solve your next problem.[/color]

              Problem with the spell checker, or some sort of censorship filter?

              Comment

              • Richard Cornford

                #8
                Re: help! user defined objects in a string...

                Lee wrote:[color=blue]
                > Richard Cornford said:[color=green]
                >> That is not how it works. If I post complete code that does
                >> what you appear to want all that will happen is that you will
                >> come back looking for copulate code to solve your next problem.[/color]
                >
                > Problem with the spell checker, or some sort of censorship filter?[/color]

                :) Spell checker. I have corrections while I type turned off on my
                user account to prevent Word from doing just that sort of stupid thing
                with my otherwise bad spelling and typos, but I was logged on as an
                administrator at the time and Word is not configured as I would like
                with that account.

                Richard.


                Comment

                Working...