使用文本框中的值到按钮形成的变量

时间:2021-03-30 20:23:04

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?

我正在尝试处理我的一个页面中的按钮,并且使用形成方法/属性搞砸了我的语法。我想让servlet路由中的'senddate'参数基于文本框中的值。我检查文本框,我得到一个值。我甚至尝试在mousedown函数上做一些警报,以确保$('#txtProcessedDate')。val()有效并获得日期。但是它不能在servlet中工作,因为它显示'$('。在这个编码语句中使用txtProcessedDate文本框值的最佳方法是什么?

  <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

谢谢您的帮助

2 个解决方案

#1


1  

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()});

#2


1  

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

你不能在形式属性中使用javascript,尝试在你更改它的地方添加keyup事件:

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

#1


1  

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()});

#2


1  

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

你不能在形式属性中使用javascript,尝试在你更改它的地方添加keyup事件:

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