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 2 of 2
  1. #1
    New to the CF scene
    Join Date
    Jun 2006
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Angry need help with script

    Hi all i have a menu editor with checkboxes to choose menu item to edit. then

    if (action=="unpublish") {
    boxes = document.menuItems.menu_item.length
    txt = ""
    for (i = 0; i < boxes; i++) {
    if (document.menuItems.menu_item[i].checked) {
    txt = txt + document.menuItems.menu_item[i].value + " "
    }
    }


    if (txt == "") {
    alert("Please select item to unpublish.");
    return ;


    } else
    document.menuItems.task.value=action ;
    document.menuItems.submit();

    }

    but if there is only one menu item in list it just alerts and fails.

    Any help?

  • #2
    Senior Coder
    Join Date
    Mar 2005
    Location
    Portsmouth UK
    Posts
    4,535
    Thanks
    3
    Thanked 513 Times in 500 Posts
    Code:
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
        "http://www.w3.org/TR/html4/loose.dtd">
    
    <html>
    
    <head>
      <title></title>
    </head>
    
    <body>
    <script language="JavaScript" type="text/javascript">
     <!--
    function Ck(){
     var boxes = document.menuItems.menu_item;
     var txt = ""
     if (!boxes.length){
      if (document.menuItems.menu_item.checked) {
       txt+=document.menuItems.menu_item.value;
      }
     }
     else {
      for (var i = 0; i < boxes.length; i++) {
       if (document.menuItems.menu_item[i].checked) {
        txt += document.menuItems.menu_item[i].value;
       }
      }
     }
     if (txt=="") {
      alert("Please select item to unpublish.");
     return ;
     }
     else {
    //  document.menuItems.task.value=action ;
    //  document.menuItems.submit();
     }
    }
    
     //-->
     </script>
    
    <form name="menuItems" >
    <input type="checkbox" value="fred" name="menu_item">
    
    <input type="button" value="Check" onclick="Ck();">
    </form>
    </body>
    
    </html>
    Vic

    God Loves You and will never love you less.

    http://www.vicsjavascripts.org/Home.htm

    If my post has been useful please donate to http://www.operationsmile.org.uk/


  •  

    Posting Permissions

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