0

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.

2
  • You need to clarify what you are doing, your current code puts an onclick handler on the entire document delegated to all span tags, when the user clicks any span tags a non-standard 'automationpath' attribute on the span tag that was clicked is looked at and then nothing happens. Commented Oct 17, 2016 at 10:59
  • I am surprise using both quotes style works " ' Redirect.jsp ' " Commented Oct 17, 2016 at 11:30

2 Answers 2

1

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

})
Sign up to request clarification or add additional context in comments.

Comments

0

I don't know what you are trying to do but if you want to change the action attribute of a form element you simply do the following:

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

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.