navas
navas

Reputation: 11

How can I get a button's value when submitted in a form?

I have a form with multiple buttons and also have a separate submit button.

When I click a button how can I disable this button and make the other button enabled? Like on/off conditions.

Also how can I get the value of the disabled button in the submitted form so I can store it in my database?

Upvotes: 0

Views: 172

Answers (3)

Rajesh Kumar
Rajesh Kumar

Reputation: 94

set id and name of the button = button1

$disabledButton = $_GET['id'];

Upvotes: 1

Thomas Clayson
Thomas Clayson

Reputation: 29925

Here's an example that might help you: http://jsfiddle.net/XHBZf/417/

When a button is clicked the styles change on all the buttons to show that one is depressed and the others are still active.

The value of that button then goes into the text field which will be submitted along with the form.

When you come to implement you can set the input as type="hidden" and it will not show up in the form.

Upvotes: 1

Loko
Loko

Reputation: 6679

You should use .prop

$('#button1').click(function () {
        $('#button1').prop('disabled', true);
        $('#button2' ).prop( "disabled", false );
    });
});

Now you have to have your buttons with the id='button1' and id='button2'

Upvotes: 0

Related Questions