1
votes

I have this JS Code:

$('#submit').click(function() {
    var res = confirm('You are about to add this Ticket Update with the following:\n\n' + $("textarea[name='ticket_update']").val() + '\n\n' + 'Time Start: ' + $("input[name='timestart_date']").val() + ' ' + $("input[name='timestart_time']").val() + '\n' + 'Time End: ' + $("input[name='timeend_date']").val() + ' ' + $("input[name='timeend_time']").val());
    if(!res) {
        return false;
    }
    else {
        document.getElementById("ticket_update").submit();
    }
});

which shows a popup box with form submitted data and if you click OK it will submit the form, otherwise cancel and go back to the form.

I want to be able to make it so: if OK is clicked on the confirm box, the form button will be disabled and the text value will change. Then the form will submit as normal

5
I see a $ here, can we assume jQuery? If so, can you tag it additionally as jQuery ?Benjamin Gruenbaum
This is JQuery syntax indeed.larssy1
Thank you - not thinking this morning :)charlie

5 Answers

1
votes

Try this, if you are using Jquery1.6 or higher version

$('#submit').click(function() {
    var res = confirm('You are about to add this Ticket Update with the following:\n\n' + $("textarea[name='ticket_update']").val() + '\n\n' + 'Time Start: ' + $("input[name='timestart_date']").val() + ' ' + $("input[name='timestart_time']").val() + '\n' + 'Time End: ' + $("input[name='timeend_date']").val() + ' ' + $("input[name='timeend_time']").val());
    if(!res) {
        return false;
    }
    else {
        $("#submit").prop('disabled', true);
        $("#submit").val("my new button label");
        document.getElementById("ticket_update").submit();
    }
});

Prop Reference

0
votes

Is this what you mean?

$('#submit').click(function() {
    var res = confirm('You are about to add this Ticket Update with the following:\n\n' + $("textarea[name='ticket_update']").val() + '\n\n' + 'Time Start: ' + $("input[name='timestart_date']").val() + ' ' + $("input[name='timestart_time']").val() + '\n' + 'Time End: ' + $("input[name='timeend_date']").val() + ' ' + $("input[name='timeend_time']").val());
    if(!res) {
        return false;
    }
    else {
        $("#submit").attr('disabled','disabled');
        $("#submit").val("my new button label");
        document.getElementById("ticket_update").submit();
    }
});

If not, what have you tried so far?

0
votes

Here is a little code snippet:

http://jsfiddle.net/XE2f6/

$('#submit').click(function() {
var res = confirm('You are about to add this Ticket Update with the following:\n\n' + $("textarea[name='ticket_update']").val() + '\n\n' + 'Time Start: ' + $("input[name='timestart_date']").val() + ' ' + $("input[name='timestart_time']").val() + '\n' + 'Time End: ' + $("input[name='timeend_date']").val() + ' ' + $("input[name='timeend_time']").val());
if(!res) {
    return false;
}
else {
    $("#submit").attr('disabled', 'disabled');
    $("#submit").val("Sending");
    $("#ticket_update").submit();
}

});

$('#ticket_update').submit(function () { confirm("Put your submit stuff here"); });

  1. Ask for confirmation
  2. Disable the button
  3. Change button value
  4. Trigger submit event on the form
  5. Catch triggered submit event on the form

Your form was in wrong format, you had to switch the double quotes for single ones, and single ones for doubles.

<form method="post" action="reviewtickets_history.php?seq=".$_GET['get']."&type=".$_GET['type']."#bo‌ttom" id="ticket_update">
<input type="text" id="input" />
<input type="submit" id="submit" value="Send!" /></form>
0
votes
$('#submit').click(function(e) {
    var res = confirm('You are about to add this Ticket Update with the following:\n\n' + $("textarea[name='ticket_update']").val() + '\n\n' + 'Time Start: ' +   $("input[name='timestart_date']").val() + ' ' + $("input[name='timestart_time']").val() + '\n' + 'Time End: ' + $("input[name='timeend_date']").val() + ' ' +    $("input[name='timeend_time']").val());
    if(!res) {
        e.preventDefault();
    }
    else {
        $("#ticket_update").submit();
    }
});
-1
votes
document.getElementById("submit").setAttribute("disabled", "disabled");

or jquery

$('#submit').click(function(e) {
  e.preventDefault();
  $('#submit').attr('disabled',true);
  //enter code here
}