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.
Page 2 of 2 FirstFirst 12
Results 16 to 29 of 29
  1. #16
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    Yep. Worked fine.

    Code:
    <html>
    <body>
    <script type="text/javascript">
    
    function calculateName(name)
    {
        return  (name.toUpperCase() + "XXX" ).replace( /[aeiou]/ig, "" ).substring(0,3);
    }
    function calculateName2(name)
    {
       return (name.charAt(0) + (name + "XXX").substring(1).replace(/[aeiou]/ig,"") ).substring(0,3).toUpperCase();
    }
    
    function demo( word )
    {
        document.write( word + "==>> (1) " + calculateName(word) + ", ==>> (2) " + calculateName2(word) + "<hr/>" );
    }
    
    demo("zamboni");
    demo("alphabet");
    demo("zoo");
    demo("oui");
    </script>
    </body>
    </html>
    Note: Both functions work for words of at least 1 letter. The second one will fail if given a word with no characters. The first one will produce "XXX".
    Last edited by Old Pedant; 11-13-2012 at 01:18 AM.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  2. #17
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Yep. Worked fine.

    Code:
    <html>
    <body>
    <script type="text/javascript">
    
    function calculateName(name)
    {
        return  (name.toUpperCase() + "XXX" ).replace( /[aeiou]/ig, "" ).substring(0,3);
    }
    function calculateName2(name)
    {
       return (name.charAt(0) + (name + "XXX").substring(1).replace(/[aeiou]/ig,"") ).substring(0,3).toUpperCase();
    }
    
    function demo( word )
    {
        document.write( word + "==>> (1) " + calculateName(word) + ", ==>> (2) " + calculateName2(word) + "<hr/>" );
    }
    
    demo("zamboni");
    demo("alphabet");
    demo("zoo");
    demo("oui");
    </script>
    </body>
    </html>
    Note: Both functions work for words of at least 1 letter. The second one will fail if given a word with no characters. The first one will produce "XXX".
    Ok thanks Guy
    Now please, Can you tell me how to use a radio button and his function checked true, false? Because in www.w3schools.com I don't find how to use it!!!!

  3. #18
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,633
    Thanks
    0
    Thanked 649 Times in 639 Posts
    Quote Originally Posted by triko View Post
    Ok thanks Guy
    Now please, Can you tell me how to use a radio button and his function checked true, false? Because in www.w3schools.com I don't find how to use it!!!!
    Not sure if w3schools would even cover how to do that since the javaScript covered there ismostly the antiquated version for Netscape 4 and earlier. The two guys who wrote the site in their spare time tried to cover so many different topics that they are struggling to keep any of them up to date and JavaScript has undergone enormous changes since they wrote their site and while they have added pages on the new commands they haven't updated the existing pages to reflect the changes in how they should be used.

    To be able to make your code interactive you will first need to get rid of the document.write statement and replace it either with innerHTML calls or proper Document Object Model calls.

    To attach processing to elements in the web page you need to be able to identify the element from the JavaScript (giving it an id and using getElementById is easiest but there are lots of other ways) and then attach an appropriate event handler or event listener to the element to specify what code to run when a specific event occursa on that element.
    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.

  4. #19
    Senior Coder
    Join Date
    Jan 2011
    Location
    Missouri
    Posts
    4,105
    Thanks
    23
    Thanked 594 Times in 593 Posts
    It's not easy, but here's how to find things on w3school:
    Main page http://www.w3schools.com/ on right is "Web References" Find and click JavaScript. Bottom of page under "HTML DOM Objects Reference" is "Input Checkbox object" click. Your on the Checkbox Object page and under "Checkbox Object Properties" is "checked" On that page is an example on setting the box, getting the state of the box and a link to a "Try it yourself" page.

  5. #20
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by felgall View Post
    Not sure if w3schools would even cover how to do that since the javaScript covered there ismostly the antiquated version for Netscape 4 and earlier. The two guys who wrote the site in their spare time tried to cover so many different topics that they are struggling to keep any of them up to date and JavaScript has undergone enormous changes since they wrote their site and while they have added pages on the new commands they haven't updated the existing pages to reflect the changes in how they should be used.

    To be able to make your code interactive you will first need to get rid of the document.write statement and replace it either with innerHTML calls or proper Document Object Model calls.

    To attach processing to elements in the web page you need to be able to identify the element from the JavaScript (giving it an id and using getElementById is easiest but there are lots of other ways) and then attach an appropriate event handler or event listener to the element to specify what code to run when a specific event occursa on that element.
    AN ok! Thanks for info! So my function checked have simple use: if female ad 40 at number of day date that i0m insert on text type, if male don't add anything and write only the number of day

  6. #21
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    Ummm...but you *ASKED* for
    Can you tell me how to use a radio button and his function checked true, false?
    And that's not as simple.

    A normal radio button, if there is only ONE of the given name=, can *NOT* be unchecked. Only checked.

    You would need some mildly sneaky JavaScript code to be able to un-check a single radio button.

    I don't think that's what you really wanted, based on your last post, but just be aware of it.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  7. #22
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    Ummm...but you *ASKED* for
    And that's not as simple.

    A normal radio button, if there is only ONE of the given name=, can *NOT* be unchecked. Only checked.

    You would need some mildly sneaky JavaScript code to be able to un-check a single radio button.

    I don't think that's what you really wanted, based on your last post, but just be aware of it.
    I badly explained, re ask my question
    So my function day contains the document.getElementById (*day that i have selected from men¨ select*) and if select radio female button, add 40 at number that i selected from men¨, else if I have selected male write only the number that I take from men¨
    I would like this method
    Code:
    <script>
    function day (myDay)
    {
    Now write that I think :)
    if (id = "male" == checked false)
    {
    var number;
    number = myDay + 40;
    }
    else (id = "male" == checked true)
    {
    var number;
    number = myDay;
    }
    alert (myDay);
    }
    </script>
    <body>
    <input type = "radio" name = "sex" id = "male" checked = "false" />
    <input type = "radio" name = "sex" id = "female" checked = "true" />
    Day: <select id = "myDay">
           <option>1</option>
           <option>2</option>
           </select>

  8. #23
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    WOW! You know, you can *NOT* just make up your own language. You have to use the language AS IT EXISTS.
    Code:
    function day(myDay)
    {
        var num = myDay;
        if ( document.getElementById("female").checked ) { num += 40; }
        alert( num );
    }
    CAUTION: This *ASSUMES* that if "female" is *NOT* checked, then "male* *IS* checked.

    If you want to be careful about it:
    Code:
    function day(myDay)
    {
        var num = "You did not check either radio button!";
        if ( document.getElementById("male").checked ) { num = myDay; }
        if ( document.getElementById("female").checked ) { num = myDay + 40; }
        alert( num );
    }
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  9. #24
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    WOW! You know, you can *NOT* just make up your own language. You have to use the language AS IT EXISTS.
    Code:
    function day(myDay)
    {
        var num = myDay;
        if ( document.getElementById("female").checked ) { num += 40; }
        alert( num );
    }
    CAUTION: This *ASSUMES* that if "female" is *NOT* checked, then "male* *IS* checked.

    If you want to be careful about it:
    Code:
    function day(myDay)
    {
        var num = "You did not check either radio button!";
        if ( document.getElementById("male").checked ) { num = myDay; }
        if ( document.getElementById("female").checked ) { num = myDay + 40; }
        alert( num );
    }
    Ok, sorry but I don't know how take to input checked!!! And it's so Easy, only add getElementById ("").checked Thanks so much my mentor Master javascript!

  10. #25
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Sorry Pedant, but what mean:
    var num = "You didn't check either radio button!";
    ???

  11. #26
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    That means they did not check EITHER Male OR Female.

    BOTH buttons were NOT CHECKED.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  12. #27
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    That means they did not check EITHER Male OR Female.

    BOTH buttons were NOT CHECKED.
    And what I need to check whether it is male or female?
    I know tht is female check

  13. #28
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    25,210
    Thanks
    75
    Thanked 4,343 Times in 4,309 Posts
    *TRY* the code I gave you.

    It looks for *BOTH* Female and Male and gives the right answer if EITHER ONE is checked.

    ONLY if NONE are checked does it give that other message.

    Or use the FIRST code I gave you instead of the second code.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  14. #29
    New Coder
    Join Date
    Oct 2012
    Location
    Italy
    Posts
    72
    Thanks
    3
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by Old Pedant View Post
    *TRY* the code I gave you.

    It looks for *BOTH* Female and Male and gives the right answer if EITHER ONE is checked.

    ONLY if NONE are checked does it give that other message.

    Or use the FIRST code I gave you instead of the second code.
    OK thanks guy <3


 
Page 2 of 2 FirstFirst 12

Posting Permissions

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