SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question string count/ chk check

    hi,
    i have two problems... would be great to have some help on this
    first... how do i count the number of characteres in a string?, must be quite simple but...

    second... i have a serie of checkBoxes, how do i make a button to check/uncheck them all?

    thanks

  2. #2
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    For checking the length of a string, use the .length method:
    Code:
    var mystr = "Hello";
    alert(mystr.length);
    For the series of checkboxes, it requires a more complicated function. This generic one will work:
    Code:
    function checkAll(checkVal)
    //pass "true" or "false" into the function and it will check
    // or uncheck all boxes, respectively
    {
      var inputs = document.getElementsByTagName("input"), i=0, current;
     while (current = inputs[i++])
     {
       if (current.type == "checkbox")
       {
         current.checked = checkVal;
       }
     }
    }
    Now, you just have to pass the value into the function; true will check them all and false will uncheck them all.

  3. #3
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    thanks

    thanks vgarcia...
    works great

  4. #4
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    another string doubt

    vgarcia, ...
    and how can i access, for expl, to the 3rd char of a certain string?

  5. #5
    ☆★☆★ silver trophy vgarcia's Avatar
    Join Date
    Jan 2002
    Location
    in transition
    Posts
    21,235
    Mentioned
    1 Post(s)
    Tagged
    1 Thread(s)
    See the other thread you made

  6. #6
    SitePoint Zealot
    Join Date
    Mar 2004
    Posts
    108
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    something a bit more complicated...

    something a bit more complicated...

    would be great you could help me on this, if u can't thanks anyway, already helped a lot..


    here's my problem
    with your help i got something like this:



    <html><head><title>Untitled Document</title>

    <script type="text/javascript">
    function lstFlip(lstBlock,lstItem) {
    if (document.getElementById(lstBlock).style.display == 'block') {
    document.getElementById(lstBlock).style.display = 'none';
    if (lstItem != undefined) {document.getElementById(lstItem).style.background = "none";}
    } else {
    document.getElementById(lstBlock).style.display = 'block';
    if (lstItem != undefined) {document.getElementById(lstItem).style.backgroundColor ="#C7C7C7";}
    }
    }

    function loadLinks(listId) {
    if (listId.length > 1){lstFlip('lstBlock'+listId.charAt(0),'lst'+ listId.charAt(0)); }
    lstFlip('lstBlock'+listId);
    }
    </script>


    <style type="text/css">
    body,a {font-family:"verdana"; font-size:12px;}
    .lstMenu {margin:0;list-style-type:none; border:1px solid #728FAD; padding:10px 0 10px 0px; width:180px; }
    .lstMenu li {cursorointer; height:25px; padding:0; margin:0;font-size:10px;}
    .lstMenu li span {width:100%; height:25px; padding:5px 0 0 15px; margin:0;}
    .lstMenu li a {font-size:12px; padding-left:20px; color:#003366; margin-left:5px; text-decoration:none; }
    .lstMenu li a:hover {font-size:12px; text-decoration:underline;}
    .lstMenu ul {display:none; list-style-type:none; margin:1px 0 1px 10px; padding:0;}
    .lstMenu ul li {background:none;margin:0; padding:0; border:0; height: 20px;}
    .lstMenu ul li a {font-size:12px; font-weight:100;}
    .lstMenu ul li a#active {color:#FF6600;}

    </style>

    </head><body>

    <ul class="lstMenu">
    <li><span id="lst1" onclick="lstFlip('lstBlock1','lst1');">Menu Item</span></li>
    <ul id="lstBlock1">
    <li><span onclick="lstFlip('lstBlock1_1');">Menu Item</span></li>
    <ul id="lstBlock1_1">
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    </ul>
    <li><a href="#" id="active">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    </ul>

    <li><span id="lst2" onclick="lstFlip('lstBlock2','lst2');">Menu Item</span></li>
    <ul id="lstBlock2">
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    <li><a href="#">menu item2</a></li>
    </ul>
    </ul>
    </body></html>
    -----------------------------------

    if i set on the page load:
    loadLinks("1");
    it gives me what i want, i load the page andthe unordered List "tree" is open where i have the link with the Id="active";
    if i can't go any further, i'll manage with this...

    what i want...
    is it possible to have a function that OnLoad searches the "lstMenu"
    for a link with the id="active",and returns the id of the "belonging" list, giving me the desired effect without passing any arguments?

    thanks either way
    if u try to do this... good luck



Bookmarks

Posting Permissions

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