2

I know it must be simple, but still I am not able to figure it out.

I have a link on a jsp page.

When this link is clicked I want another tab (of browser) to open up.

The view of this new page is defined by action class, which needs a form field value.

The problem I am facing is that I can not get the values of form fields to the action class without submitting the form. And submitting the form changes the view of the original jsp as well, which defeats the whole purpose of opening a new tab.

So I need a way to get the form field values to action class without resetting the view of original jsp page.

One way I came across was URL re-writing but that would be my last option.

Please suggest something!!

Thanks!!

kanishk
  • 713
  • 4
  • 15
  • 31

2 Answers2

1

Firstly I would like to point out that currently possible (to my knowledge anyway) to force a new tab to appear, it is dependent on the users' browser and the settings that they have see here for more infomation.

Now onto your question, since links cannot send form data (on their own) you have 2 options:

  1. You can use a form "submit" button pointing to the URL you want to send the data to and to and add the target="_blank" to the form which will cause a new page to open up when the form is submitted.
  2. You can add a javascript event to your link so that when it is pressed you append the value of the input to the URL and open a new window with that URL.

Personally I would choose the first option.

Here is a simple example of option one which doesn't remove the input value when you submit...

<html>
  <body>
    <form action="test1.html" method="post" target="_blank">
      <input type="text" name="bob" />
      <input type="submit" value="Hello"/>
    </form>
  </body>
</html>
Community
  • 1
  • 1
slc84
  • 61
  • 3
  • I have already tried option one. The problem there is that the original page (the one from which the link is clicked) gets refreshed as well. I do not want that. And I am not too comfortable with the second option, though if you have a quick code for that I would like to try it. – kanishk May 09 '12 at 12:30
  • @kanishk Are you sure you have done option one correctly? It didn't do that when I tried the simplest example - the value was kept... – slc84 May 09 '12 at 13:21
  • Hey, Thanks man. I was putting blank,_blank in the link's target attribute. Doing the same for form worked like a charm. – kanishk May 10 '12 at 04:48
0

You could do an ajax call, or dynamically build the link url with get parameters in it.

aglassman
  • 2,643
  • 1
  • 17
  • 30