Results 1 to 4 of 4

Thread: Help Needed Disabling Buttons

  1. #1

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Help Needed Disabling Buttons

    I have a task allocation program that allocates tasks to employees.

    The page looks like this:
    userid projid TaskID Logon/Logoff
    userid projid TaskID Logon/Logoff
    userid projid TaskID Logon/Logoff
    userid projid TaskID Logon/Logoff

    As you can see a user can see all his/her tasks but I want them to log on to a task & all the other tasks logon buttons should be disabled.

    How do I disable them??

  2. #2
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help Needed Disabling Buttons

    Do you want it disabled already or disabled when they do something on the page? If the former you can just add disabled="disabled" as an attribute of the button. If the latter you will need to use setAttribute() in Javascript.

  3. #3

    Thread Starter
    New Member
    Join Date
    Jul 2006
    Posts
    2

    Re: Help Needed Disabling Buttons

    Yes if a user clicks logon it should disable all other logon buttons.

    I have not used Java script before could you elaborate??

    Here is my function that reacts on the button click:
    function processTask()
    {
    if ( $str1 = whichButton($_POST, "Log On")){
    $IdArray = explode("|",$str1);
    $sql = "INSERT INTO EmpTaskLog(Logon, EmpID, TaskID) VALUES (NOW(),\"$IdArray[0]\",$IdArray[1]);";
    $res = mysql_query( $sql ) or die ( 'Unable to execute query.' );

    # // Redirect the page
    $nURL = $URL."index.php";
    header ("Location: $nURL");
    }
    elseif ($str = whichButton($_POST,"Log Off")) {
    printf ("<form action='t_comp.php?tup=$str' method='post'>\n");
    printf ("<h2><center>Task Percentage Complete:</h2></center>");
    printf ("<h2><center><input name='perc' size='5' border='2'></h2></center>\n");
    printf ("</form>\n");
    }
    }

  4. #4
    I'm about to be a PowerPoster!
    Join Date
    Jan 2005
    Location
    Everywhere
    Posts
    13,647

    Re: Help Needed Disabling Buttons

    Using Javascript it is very simple you just need a reference to the DOM node. There are several ways to get a node reference, you can use getElementById() if the element has an id attribute specified, or you can use getElementsByTagName to get all elements of one type. Which method you use depends upon which suits your page structure best. You may find you have to add IDs to the elements in the PHP code.

    Once you have a DOM node reference you can then use the setAttribute() method to disable it.

    Code:
    // if inputButton is a node reference to an <input> element
    
    inputButton.setAttribute('disabled', 'disabled');

Posting Permissions

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



Click Here to Expand Forum to Full Width