简体   繁体   中英

Struts action should be open as popup onclick of a href link

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

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"?

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.

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