SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast
    Join Date
    Dec 2006
    Posts
    88
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Javascript conflict

    Hello evrybody,

    First of all, I know nothing about Java script.
    I have this script that works fine and the script checks all checkboxes and if the checkboxes are selected it redirect it and in the file delete.php I delete checked rows.
    Code JavaScript:
    function goDel()
    {
        var recslen =  document.forms[0].length;
        var checkboxes=""
        for(i=1;i<recslen;i++)
        {
            if(document.forms[0].elements[i].checked==true)
            checkboxes+= " " + document.forms[0].elements[i].name
        }
     
        if(checkboxes.length>0)
        {
            var con=confirm("Are you sure you want to delete");
            if(con)
            {
                document.forms[0].action="delete.php?recsno="+checkboxes
                document.forms[0].submit()
            }
        }
        else
        {
            alert("No record is selected.")
        }
    }
     
    function selectall()
    {
    //        var formname=document.getElementById(formname);
     
            var recslen = document.forms[0].length;
     
            if(document.forms[0].topcheckbox.checked==true)
                {
                    for(i=1;i<recslen;i++) {
                    document.forms[0].elements[i].checked=true;
                    }
        }
        else
        {
            for(i=1;i<recslen;i++)
            document.forms[0].elements[i].checked=false;
        }
    }

    Then in php file I call this java script by

    PHP Code:
    <form action="" method="post" name="" id="">
    <input name="<? echo $row['id']; ?>" type="checkbox" class="check">
    <a href="javascript:goDel()">Delete</a></form
    It works fine but when I have another javascript it has a conflict somewhere with other java scripts and it works only when it's alone.
    When there is a conflict I always get message "No record is selected." in spite of that the records are selected.
    How can I change this script so it works with other java scripts?
    Many thanks.

  2. #2
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,729
    Mentioned
    104 Post(s)
    Tagged
    4 Thread(s)
    It would help to know that other scripts are conflicting with it.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  3. #3
    SitePoint Wizard Stomme poes's Avatar
    Join Date
    Aug 2007
    Location
    Netherlands
    Posts
    10,283
    Mentioned
    51 Post(s)
    Tagged
    2 Thread(s)
    And would help how you are executing these (where are they set in the HTML?).


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
  •