-1

I have a set of radio buttons. When one of the options is selected, I want it to redirect to a Struts action.

<form name=termDDL>
            <s:iterator value="filterOptions" var="a">
            <%String [] parts = request.getAttribute("a").toString().split(":"); %>
                <input type="radio" name="selectedOption" value="a" onclick="onOptionSelect()"><%=parts[0]%> <h6 style="color:gray;display: inline;"> <%=parts[1]%></h6><br>

                </s:iterator>
            </form>

And the javascript function onOptionSelected() is defined as follows just before the closing of the body tag.

<script type="text/javascript">
    function onOptionSelect() {
        //document.getElementById("courseDisplayChoice").selectedIndex = 0;
        document.termDDL.action = 'displayProductsInRange.action';
        document.termDDL.submit();
    }
    </script> 

But this is not redirecting to the struts action. And I do not want to use a submit button for the same. How do I accomplish this without clicking a submit button?

Roman C
  • 49,761
  • 33
  • 66
  • 176
SoulRayder
  • 5,072
  • 6
  • 47
  • 93
  • http://stackoverflow.com/questions/8970600/how-to-navigate-to-a-different-page-with-javascript – JB Nizet Apr 12 '15 at 09:40
  • Its not redirecting to the struts action at all – SoulRayder Apr 12 '15 at 09:42
  • There is no redirection to make. You're on a page with a given URL, and you want to go to another page with another URL. This other URL should be the URL to which the struts action is mapped. What's the problem? – JB Nizet Apr 12 '15 at 09:44
  • I am giving the same name of the action as defined in my struts.xml, and yet it is not going into the action class's method at all – SoulRayder Apr 12 '15 at 09:47
  • Go to the page you would like to "redirect" to. Copy the URL of that page, displayed in the address bar of the browser. Paste it in your code. – JB Nizet Apr 12 '15 at 09:49
  • Got my mistake thanks :) After submitting my question , I tried using onSelect instead of onClick and it was not working – SoulRayder Apr 12 '15 at 09:52

1 Answers1

0

You can use window.location for redirecting from client side to anywhere.

function onOptionSelect() {
    //document.getElementById("courseDisplayChoice").selectedIndex = 0;
    window.location = '/displayProductsInRange.action';
}
hamed
  • 7,939
  • 15
  • 60
  • 114