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 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    displaying javascript result in column

    using a javascript function to determine if a string is all digits or not and return result based off the decision. if it is all digits, mask all digits except the first two, if not all digits just return the string.

    these are the snippets however i am not seeing anything returned in the column

    Code:
    <script >
    
    
    var start = function RenderRC(CodeOwner) {
    
            var Rcode = CodeOwner.toString();
    
            var pattern = new RegExp("^\d{2,}$ ");
    
            if (Rcode.match(pattern)) {
    
                if (Rcode.length > 2)
                 {
                    var newcode = Rcode.substr(0, 2) + Array(Rcode.length - 2 + 1).join("*");
                    return newcode;
                }
    
            }
              else 
            {
                   return Rcode; 
            }
            
        };
    
    </script>
    
     <ext:RecordField Name="CodeOwner" />
    
    
     <ext:Column Header="<%$ Resources:Text, CodeOwner %>"DataIndex="CodeOwner" Width="110" >
                    <Renderer Fn ="start" />
                    </ext:Column>

  • #2
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 633 Times in 623 Posts
    What does the HTML look like?
    Stephen
    Learn Modern JavaScript - http://javascriptexample.net/
    Helping others to solve their computer problem at http://www.felgall.com/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #3
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Code:
    <script type = "text/javascript"> 
    
    function a(str) {
    if (/\D/gi.test(str)) {
    return str;  // non-digits found
    }
    var len = str.length;
    var newstr = str.substring(0,2);
    var rest = str.substring(2);
    rest = rest.replace(/\d/g,"*");
    newstr += rest;
    return newstr;
    }
    
    alert  (a("1234567"));
    
    </script>

    If he'd had a clear view I think he would have seen it. - Commentator Sky Sports 1

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.

  • #4
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    thanks so far, but i am still not sure how to return it to have it displayed in the column...

  • #5
    New to the CF scene
    Join Date
    Apr 2012
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Philip M View Post
    Code:
    <script type = "text/javascript"> 
    
    function a(str) {
    if (/\D/gi.test(str)) {
    return str;  // non-digits found
    }
    var len = str.length;
    var newstr = str.substring(0,2);
    var rest = str.substring(2);
    rest = rest.replace(/\d/g,"*");
    newstr += rest;
    return newstr;
    }
    
    alert  (a("1234567"));
    
    </script>

    If he'd had a clear view I think he would have seen it. - Commentator Sky Sports 1

    thanks so far but i still not having anything returned to the column, is that what the "alert" is for?

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    Quote Originally Posted by cheaven View Post
    thanks so far but i still not having anything returned to the column, is that what the "alert" is for?
    No,the alert is simply for test/demonstration purposes. As felgall says, we need to see the (relevant) HTML code before we can go any further.

    All the code given in this post has been tested and is intended to address the question asked.
    Unless stated otherwise it is not just a demonstration.


  •  

    Tags for this Thread

    Posting Permissions

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