简体   繁体   中英

pass js variable to form action

I have a dynamic variable in js. I have to get this variable in my form action. Here is my code

<script type="text/javascript">
    $(document).on('click', 'span', function () {

    var AutoPath = $(this).attr('automationpath');
    // or var AutoPath="Redirect.jsp";
    }
</script>

<form action="%{#AutoPath}" method="get">

    <input name="AutoRun" id="AutoAction" value="Auto Action" type="submit"  />
</s:form>

But this does not redirect to the Redirect.jsp page

If I manually set as below, it will redirect to the Redirect.jsp

<s:set var="formAction" value="'Redirect.jsp'" />
<s:form action="%{#formAction}" >

    <input name="AutoRun" id="AutoAction" value="Auto Action" type="submit"  />
</s:form> 

Can somebody help me with this.

In your javascript code, you are not inserting the automation path into your markup.

Instead the code should look something like this:

$(document).on('click', 'span', function () {

     //saving the value to variable
     var AutoPath = $(this).attr('automationpath');

     //Inserting value int he form
     $('form').attr('action', autoPath);

})

我不知道您要做什么,但是如果您想更改表单元素的action属性,则只需执行以下操作:

 $('form').attr('action','Redirect.jsp');

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM