Win a copy of Learn Spring Security (video course) this week in the Spring forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

2 questions about confirm() and onsubmit()

 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
1.
Here is my problem ...
I have a page, thats ask visitor to print this page or not.
If visitor clicks OK, browser print dialog is appeared, and after printing there is appearing new one confirm() function, that doing redirect on other page.
Problem: when I click IN BROWSER PRINT DIALOG BUTTON "CANCEL"- all OK, function gar() is calling and appearing confirm() function.
But if I click IN BROWSER PRINT DIALOG BUTTON "PRINT" , browser prints page AND gives me 2 (TWO!!) confirmations at one time: "Print?" and "Do u want make warranty?"
I have a javascript that looks like this:
---------------------------------------------------
if (confirm("Print?"))
{
window.print();
gar();
}
else
{
window.close();
}

function gar() {
if (confirm("Do u want to make warranty?"))
{
document.myForm.submit();
}
else
{
window.location.href = "cash.jsp"
}
}
-------------------------------------
2.
I have a form and onsubmit i want to open a new window with form variables..
here is a code:
---------------------------------------
function newWindow(){
formWindow = window.open("my.jsp", "ladu",width="300,height=300" )
return false;
}
------------------------------------------------
and html:
<FORM ONSUBMIT="newWindow();" action="my.jsp" method="post">
//form stuff
<INPUT TYPE="SUBMIT" name="submit" value="submit">
</form>
--------------------------------------------------
but variables that i have in my form on first page are not passing in my.jsp
(exactly, I have a SELECT menu)
p.s. if I posting this form in the same window - all going ok..
 
Tomasz Piasecki
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Q1.: It seems to me like you are calling 2 methods window.print() and gar() on confirm"Print?", one by one. Therefore, firstone is opening the browser Print box and you are able to print it out, and then right away you are calling the gar() method (see your code:
if(confirm "Print?"{
window.print();
gar():
}
else ...
That is why you are getting confimation of succesfull print, and at the same time (almost :-) the info "Do you want the Warranty?" thing.
Try to put the call to gar() method after "else" before window.close();
or do the "else if{ gar();}" before the last else.
Q.2: Look at your opening parents(") by the width:
newWin = window.open("my.jsp", "ladu",width="300,height=300" )
I think it should be:
newWin = window.open("my.jsp", "ladu","width=300,height=300")
and maybe add:
void(this, 'null');
newWin.focus();
so it will protect your main page to disepear, and will set the focus in the new Window.
I hope it will help.
 
Ilja Smoli
Ranch Hand
Posts: 64
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Tomasz Piasecki:
Q.2: Look at your opening parents(") by the width:
newWin = window.open("my.jsp", "ladu",width="300,height=300" )
I think it should be:
newWin = window.open("my.jsp", "ladu","width=300,height=300")
and maybe add:
void(this, 'null');
newWin.focus();
so it will protect your main page to disepear, and will set the focus in the new Window.
I hope it will help.

About Q.2.:
Thx a lot for ur reply, but variables are not passing from this form to new popup window
Any ideas?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic