3

I have a while loop that fetches data from a database. I have made three buttons:

> Open  
> Hold   
> Close

The first time when the page loads, only the open button should be enabled, and the others should be disabled.

After I click the open button, the open button should be disabled, and the hold and close buttons should be enabled.

I got this result for only one row, but in the while loop not for all the rows.

I have used JavaScript with php.

Example:

function onload()
{
    document.getElementById("Hold").disabled = true;
    document.getElementById("close").disabled = true;
    return false; 
}

The above code was working for the first row, but I need it to work for all the while loop values.

1
  • Include a sample of your markup. Commented Jan 3, 2012 at 13:13

2 Answers 2

6

Your problem lies in that you are using the same ID for multiple elements - ID's must be unique to each element, and thus, getElementById returns ONE element, with that ID. Give them classes instead.

Sign up to request clarification or add additional context in comments.

Comments

2

HTML

<input type="button" value="Open" id="openButton" name="openButton">
<input type="button" value="Hold" id="holdButton" name="holdButton" disabled="disabled">
<input type="button" value="Close" id="closeButton" name="closeButton" disabled="disabled">

jQuery

$(document).on('click','input[type=button]', function() {
               buttonVal = $(this).val();
    if(buttonVal == 'Open' )
    {
        $(this).prop("disabled", true);
        $('#holdButton,#closeButton').prop("disabled", false);
    }
    else
    {
         $('#holdButton,#closeButton').prop("disabled", true);
         $('#openButton').prop("disabled", false);
    }
});

DEMO

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.