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 11 of 11

Thread: Help plz

  1. #1
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Help plz

    i have two questions

    1)
    i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function


    2)

    A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function


    i hope any1 will write me those scripts.
    Thanks all of u

  • #2
    Regular Coder
    Join Date
    May 2008
    Location
    Lost in Localhost...
    Posts
    702
    Thanks
    3
    Thanked 43 Times in 42 Posts
    Quote Originally Posted by wavyado View Post
    i have two questions

    1)
    i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function


    2)

    A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function


    i hope any1 will write me those scripts.
    Thanks all of u
    Were here to help not to do everything for you.
    If you don't know how to do it then I suggest you learn.

    Unless you want to start it and we can help you.

  • #3
    New Coder
    Join Date
    Feb 2005
    Posts
    97
    Thanks
    7
    Thanked 7 Times in 7 Posts
    Quote Originally Posted by wavyado View Post
    i have two questions

    1)
    i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function


    2)

    A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function


    i hope any1 will write me those scripts.
    Thanks all of u
    1: I want you to make some sense.

    2: I want you to make some effort.

  • #4
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Millenia View Post
    Were here to help not to do everything for you.
    If you don't know how to do it then I suggest you learn.

    Unless you want to start it and we can help you.

    in the 1st question

    <html>
    <head>
    <script>
    function Convert(){

    var a=document.f.t1.value;
    var b=document.f.t2.value;
    var i;

    for(i=0;i<=a.length;i++)
    {
    document.f.t2.value=b.replace(a.charAt(i),"x");
    }







    }


    </script>
    </head>

    <body>
    <form name="f">
    <table>
    <tr>
    <td>Enter <td><input type=text name="t1">
    </tr>

    <tr>
    <td>Enter <td><input type=text name="t2">
    </tr>

    <tr>
    <td><input type=button value=convert onClick="Convert()">
    </tr>




    </table>

    </form>

    </body>
    </html>


    the second 1

    var a=document.f.t1.value;

    var i;

    for (i = 0; i < a.length; i++)
    {
    var c = a.charAt(i);

    if (!isDigit(c))


    {alert("adsads");}
    }



    so are they right ?

  • #5
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by mattyod View Post
    1: I want you to make some sense.

    2: I want you to make some effort.
    in the 1st question

    <html>
    <head>
    <script>
    function Convert(){

    var a=document.f.t1.value;
    var b=document.f.t2.value;
    var i;

    for(i=0;i<=a.length;i++)
    {
    document.f.t2.value=b.replace(a.charAt(i),"x");
    }







    }


    </script>
    </head>

    <body>
    <form name="f">
    <table>
    <tr>
    <td>Enter <td><input type=text name="t1">
    </tr>

    <tr>
    <td>Enter <td><input type=text name="t2">
    </tr>

    <tr>
    <td><input type=button value=convert onClick="Convert()">
    </tr>




    </table>

    </form>

    </body>
    </html>


    the second 1

    var a=document.f.t1.value;

    var i;

    for (i = 0; i < a.length; i++)
    {
    var c = a.charAt(i);

    if (!isDigit(c))


    {alert("adsads");}
    }



    so are they right ?

  • #6
    Supreme Master coder! _Aerospace_Eng_'s Avatar
    Join Date
    Dec 2004
    Location
    In a place far, far away...
    Posts
    19,291
    Thanks
    2
    Thanked 1,043 Times in 1,019 Posts
    Does it work?
    ||||If you are getting paid to do a job, don't ask for help on it!||||

  • #7
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so will any1 help me or what ?

  • #8
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    First of all, try to change your title, make it a little bit descriptive as to the problem you're experiencing right now.

    Secondly, your question is confusing.

    Quote Originally Posted by wavyado View Post
    [B]
    1) i wanna a javascript function that replaces all letters in a string by "x". Then a script that will use this function
    2) A javascript function that return 'true' when a string contains at least one digit. Then write a script that will use this function

    For the first one, you can do a global replace:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('test');
    el.firstChild.nodeValue=el.firstChild.nodeValue.replace(/[a-z\d]/gi,'x');
    }
    </script>
    <p id="test">
    The quick brown fox jumps over the lazy dog.
    </p>
    ...but the second statement in your first question does'nt makes sense.

    For your second question:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('test');
    alert((el.innerHTML.length>0)?'Great! You have long characters.':'Please lengthen your characters.');
    }
    </script>
    <p id="test">
    The quick brown fox jumps over the lazy dog.
    </p>
    The second statement is confusing still.

    And for the last one:
    Quote Originally Posted by wavyado View Post
    so will any1 help me or what ?
    Patience is a virtue, and it seemed you are not living on it.

    Hope that makes sense.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    wavyado (09-29-2008)

  • #9
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rangana View Post
    First of all, try to change your title, make it a little bit descriptive as to the problem you're experiencing right now.

    Secondly, your question is confusing.




    For the first one, you can do a global replace:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('test');
    el.firstChild.nodeValue=el.firstChild.nodeValue.replace(/[a-z\d]/gi,'x');
    }
    </script>
    <p id="test">
    The quick brown fox jumps over the lazy dog.
    </p>
    ...but the second statement in your first question does'nt makes sense.

    For your second question:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('test');
    alert((el.innerHTML.length>0)?'Great! You have long characters.':'Please lengthen your characters.');
    }
    </script>
    <p id="test">
    The quick brown fox jumps over the lazy dog.
    </p>
    The second statement is confusing still.

    And for the last one:


    Patience is a virtue, and it seemed you are not living on it.

    Hope that makes sense.
    First of all, Thanks very much rangana, i really owe u, cause u really helped me in the first question, and in the secod question, which is :

    A javascript function that return 'true' when a string contains at least one digit.

    for example: if you entered a string,let say "can any1 help" so this string contain the "1" digit, in this case, an alert prompt that this string contain a digit.

    and relating 4 the 1st question, in /[a-z\d]/gi, i understand a-z is that all Character between a and z, but i didnt understand the \d and the /gi,to what they refer ?

    Hope you wuill again answer my questions.

    Thanks for your help and your cooperation

  • #10
    Senior Coder rangana's Avatar
    Join Date
    Feb 2008
    Location
    Cebu City, Philippines
    Posts
    1,752
    Thanks
    65
    Thanked 372 Times in 365 Posts
    Use this instead:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('test');
    alert((el.innerHTML.match(/\d/g))?'Great! You have a digit on it.':'Sorry, there\'s no digit on it.');
    }
    </script>
    <p id="test">
    The quick brown fox jumps over the lazy dog.
    </p>
    \d matches a digit, the same as you do [0-9].

    gi are modifier which stands for global pattern matching and case-insensitive pattern matching respectively.

    Hope that makes sense.
    Learn how to javascript at 02geek

    The more you learn, the more you'll realize there's much more to learn
    Ray.ph

  • Users who have thanked rangana for this post:

    wavyado (09-30-2008)

  • #11
    New to the CF scene
    Join Date
    Sep 2008
    Posts
    6
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by rangana View Post
    Use this instead:
    Code:
    <script type="text/javascript">
    window.onload=function(){
    var el=document.getElementById('test');
    alert((el.innerHTML.match(/\d/g))?'Great! You have a digit on it.':'Sorry, there\'s no digit on it.');
    }
    </script>
    <p id="test">
    The quick brown fox jumps over the lazy dog.
    </p>
    \d matches a digit, the same as you do [0-9].

    gi are modifier which stands for global pattern matching and case-insensitive pattern matching respectively.

    Hope that makes sense.
    Thanks rangana, You Really helped me. I wish some day i can help you


  •  

    Posting Permissions

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