Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts

    How do you change bg color when Text is auto filled into text Field?

    So I have figured out from a guy on here that this code lets you change the BG Color when certain text is enter into a text field. It works just fine.

    But now what I need help with is what Java Script statement do I use if the field has text automatically enter into the field. I need the same thing to happen the BG Color to change a different color depending on what text has been auto filled.

    If someone knows what extra code I would need to enter to make this work
    Thanks to all who can help.

    <body>
    <input type="text" name="fld1" id="fld1" onkeyup="changeBG(this.value)"/><br />
    <input type="text" name="fld2" id="fld2" onkeyup="changeBG1(this.value)"/><br />
    <input tupe="text" name="fld3" id="fld3" onkeyup="changeBG(this.value)"/><br />
    <script>
    function changeBG(val){
    var colors={"AMDML":"red","MA":"green","SPN":"black"};
    for(i in colors){
    if(val.match(i)){
    document.body.style.backgroundColor=colors[i];
    }
    }
    }
    </script>

    <script>
    function changeBG1(val){
    var colors={"AMDML":"blue","CA FANNIEMAE MA":"green","BCRA ETRADE":"black"};
    for(i in colors){
    if(val.match(i)){
    document.body.style.backgroundColor=colors[i];
    }
    }
    }
    </script>

    </body>

  • #2
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Use the windows.onload command to run the function supplying the value (document.forms["formname"].fld1.value).
    ^_^

    If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
    *
    The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".

  • Users who have thanked WolfShade for this post:

    chris77780124 (06-18-2012)

  • #3
    New to the CF scene
    Join Date
    Jun 2012
    Posts
    8
    Thanks
    5
    Thanked 0 Times in 0 Posts
    I'm confused you want me to replace the document.body.style.backgroundColor=colors[i]; with the code you wrote?
    document.forms["formname"].fld1.value

    Let me know if I'm correct. Thanks

    \<script>
    function changeBG1(val){
    var colors={"AMDML":"blue","CA FANNIEMAE MA":"green","BCRA ETRADE":"black"};
    for(i in colors){
    if(val.match(i)){
    document.forms["formname"].fld1.value

    }
    }
    }
    </script>

  • #4
    Senior Coder xelawho's Avatar
    Join Date
    Nov 2010
    Posts
    2,918
    Thanks
    56
    Thanked 545 Times in 542 Posts
    it will depend on how the text "automatically" gets filled. text inputs have an onchange event, but this doesn't fire until the input loses focus (so is kind of useless imo) - you will probably have to fire the function from the function that sends the text, but without seeing that, it's hard to say.

  • Users who have thanked xelawho for this post:

    chris77780124 (06-19-2012)


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •