Reputation: 720
I have two javascript functions as shown below
<body>
<script language="javascript">
function generate(){
var table = document.getElementById('my_table');
var rowCount = table.rows.length;
var f = document.form;
f.target = "_blank";
f.method="post";
f.action='ViewPO.jsp?rowCount='+rowCount;
f.submit();
}
function generate1(){
var table = document.getElementById('my_table');
var rowCount = table.rows.length;
var f = document.form;
f.method="post";
f.action='purchaseAction.jsp?rowCount='+rowCount;
// f.submit();
}
<input type="submit" value="Save" onclick="generate1()" />
<input type="submit" value="View PO" onclick="generate()"/>
I have given f.target="_blank"
for one javascript function.when i click on "View PO" button it is opening in another tab of the browser which is very good.but when i close that tab and immediately click on "Save" it is also opening in another tab of the browser which i dont need it in the sense it should open the page in the same tab.So any help will be appreciated.
Upvotes: 0
Views: 28
Reputation: 68413
add f.target = "_self";
in your generate1()
function as
function generate1(){
var table = document.getElementById('my_table');
var rowCount = table.rows.length;
var f = document.form;
f.method="post";
f.target = "_self";
f.action='purchaseAction.jsp?rowCount='+rowCount;
// f.submit();
}
target property that was set in the form by generate()
was used by the form in generate1()
method so you need to reset the same to default which is _self
.
Upvotes: 2
Reputation: 388406
That is because calling generate
will set the target
value of the form
to _blank
, this value is saved to the form's properties so when generate1
is called it uses the same target value.
So just reset the value of target
property in generate1
function generate1() {
var table = document.getElementById('my_table');
var rowCount = table.rows.length;
var f = document.form;
f.method = "post";
f.target = "";
f.action = 'purchaseAction.jsp?rowCount=' + rowCount;
// f.submit();
}
Upvotes: 2