Meaningless Drivel is fun!*
The moose likes HTML, CSS and JavaScript and the fly likes 2 questions about confirm() and onsubmit() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "2 questions about confirm() and onsubmit()" Watch "2 questions about confirm() and onsubmit()" New topic
Author

2 questions about confirm() and onsubmit()

Ilja Smoli
Ranch Hand

Joined: Dec 02, 2001
Posts: 64
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

Joined: Dec 14, 2001
Posts: 9
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

Joined: Dec 02, 2001
Posts: 64
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?
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: 2 questions about confirm() and onsubmit()