0

I have a form on my jsp,

<form  action="test1_action" name="test" method="post" id="test">

also I have two different link link1, link2 here,

onclick of link1 I should submit test1_action action

$('#link1').click(function() {  
        document.forms['test'].action='test1_action';
        document.forms['test'].submit();
}); 

This works perfect for me.

what My expectation is when I click the second link popup should open with different action something like follows below.

$('#link2').click(function() {
        document.forms['test'].action='**different_action**';
        document.forms['test'].submit();
});
Cœur
  • 37,241
  • 25
  • 195
  • 267
user1060990
  • 179
  • 1
  • 2
  • 8

2 Answers2

0

You are using jQuery so there is no need for manual DOM traversal:

$('#link1').click(function() {  
  $('#test').attr('action', 'test1_action').submit();
}); 

$('#link2').click(function() {  
  $('#test').attr('action', 'test2_action').submit();
}); 

The action attribute defines the page to which the form sends its contents, most commonly a page that interfaces with the server in some way (PHP, JSP, etc.).

What do you mean by "popup"?

Blender
  • 289,723
  • 53
  • 439
  • 496
  • I really appreciate for your responce, here I want to show as Popup window something like this. **window.open(**test2_action**,"_blank","directories=no, status=no,width=600, height=700,top=0,left=0");** – user1060990 Nov 23 '11 at 03:03
  • So you'd like to submit the form and open that new window *while on the same page* (without refreshing)? – Blender Nov 23 '11 at 03:04
  • Yes blendar you got it but I'd like to open as a new popup window with abouve mentioned width and height. Thanks – user1060990 Nov 23 '11 at 03:09
0

You can use window.open() to open a window with a specific name, and then use that name as the target for the form submit.

$('#link2').click(function() {
   window.open("","test2win","directories=no,status=no,width=600,height=700,top=0,left=0");

   $('#test').attr({
     'action' : 'test2_action',
     'target' : 'test2win'
   }).submit();
});

I'm not sure that the above will work in all browsers though. If not, you might have to just forget the window.open() step and just submit the form with target=_blank and then set the size from within the page being returned from the submit.

nnnnnn
  • 147,572
  • 30
  • 200
  • 241
  • **Window.open** it doesn't work, also I'm trying to set Height and width for **test2win** added Style for the page something like this
    html,body {
    height: 700px; width: 600px;
    } thats also sucks me... any thoughts on this.
    – user1060990 Nov 23 '11 at 04:13
  • I don't think you can change the browser window size from CSS. You need to use the `window.resizeTo()` function from JavaScript in the new page (and possibly `window.moveTo()` if you want to centre the window). – nnnnnn Nov 23 '11 at 04:42
  • great... do you think this will work, because consider I'm working with some 10 different pages / Tabs on firefox, if I use this **window.resizeTo()** then all other pages would be resized right.. correct me If I'm wrong... Thanks – user1060990 Nov 23 '11 at 05:26
  • Some browsers ignore calls to `window.resizeTo()` if there is more than one tab open, but for those that don't: yes, it will affect all open tabs. I don't really recommend it in general, but it's there if you need it. One of the answers in the following thread uses `window.open`: http://stackoverflow.com/questions/178964/javascript-post-on-form-submit-open-a-new-window – nnnnnn Nov 23 '11 at 05:33
  • No luck Mr.nnnnn.., any other thoughts would be really appreciated. Thanks – user1060990 Nov 23 '11 at 05:58