Reputation: 631
i have a form in html with two submit buttons either one is enabled. if user is filling the form submit is enabled and the other button is diasbled. when user clicks submit button other button gets enabled and displays all the field values with read only .when the 2nd button is clicked values are enterd in databse, using jquery or javascript is it possible
$('input[type="text"]').each(function(){
$(this).attr('readonly','readonly');
});
Upvotes: 0
Views: 88
Reputation: 13803
If I read your question correctly, the first button does not actually submit the form?
$("#firstbutton").click(function() {
$("#myForm input").attr("readonly", "readonly"); //this makes the input fields readonly
$("#secondbutton").attr("disabled","disabled"; //this enable the second button
$(this).removeAttr('disabled'); //this disables the #firstbutton
}
Make sure that:
<input>
but <select>
items.type="submit"
, it should either be of type="button"
or be a <button>
tag instead.disabled
attribute on your input fields. If you do, the form submit will ignore these fields and not post them as intended. You're already doing it right by using readonly.Upvotes: 1
Reputation: 24276
$(document).ready(function(){
$('#myForm').submit(function(e){
e.preventDefault();
$myForm = $(this);
$myForm.find('input[type=submit]').attr('disabled','disabled');
$myForm.find('input#other-button').attr('enabled','enabled');
//do a $.post request
$.post('/path/to/my-file.php',
$myForm.serialize(),
function(data){
// make something after the post is complete
$myForm.find("input[type=text]").attr('readonly','readonly');
},
'json');
});
});
Upvotes: 0