hammerva
hammerva

Reputation: 139

Using value from text box to a variable on a button formaction

I am trying to work on a button in one of my pages and my syntax is messed up using the formaction method/attribute. I wanted to have the ‘senddate’ parameter in the servlet routing be based on a value in a text box. I check the text box and I am getting a value. I even tried doing some alerts on a mousedown function to make sure that $('#txtProcessedDate').val() is valid and got the date. But it isn’t working in the servlet as it shows '$('. What is the best way to use the txtProcessedDate text box value in this formaction statement?

  <button style="margin-left:20%; font-weight:bold" id="updatePayment" 
            type="submit" 
            formaction="EFTscreen?action=routeEFTC&senddate=$('#txtProcessedDate').val() "
            class="btn btn-success bold">Update Payment Status
  </button>

Thanks for the help

Upvotes: 0

Views: 47

Answers (2)

jcubic
jcubic

Reputation: 66518

You can't have javascript in formaction attribute, try to add keyup event where you change it:

$('#txtProcessedDate').keyup(function() {
    var url = "EFTscreen?action=routeEFTC&senddate=";
    $("#updatePayment").attr("formaction",  url + $(this).val());
});

Upvotes: 1

Velimir Tchatchevsky
Velimir Tchatchevsky

Reputation: 2815

What you have is not the right way to concatenate the value to the text of the attribute value. You can do it like so:

$("#updatePayment").attr({"formaction": $("#updatePayment").attr("formaction")+"&senddate="+$("#txtProcessedDate").val()});

Upvotes: 1

Related Questions