HighDots Forums  

Click submit button without refresh

Javascript JavaScript language (comp.lang.javascript)


Discuss Click submit button without refresh in the Javascript forum.



Reply
 
Thread Tools Display Modes
  #1  
Old   
SamuelXiao
 
Posts: n/a

Default Click submit button without refresh - 11-03-2009 , 09:14 AM






Hi,

I am trying to submit a form in a parent window by using its child
window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
window.opener.document.getElementById("btn1").clic k();
window.close();
}

The code works for submitting but the parent window always refresh
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.

I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.

Is there any way I can prevent it refreshing the page after click()?

Reply With Quote
  #2  
Old   
Erwin Moller
 
Posts: n/a

Default Re: Click submit button without refresh - 11-03-2009 , 09:42 AM






SamuelXiao schreef:
Quote:
Hi,

I am trying to submit a form in a parent window by using its child
window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
window.opener.document.getElementById("btn1").clic k();
window.close();
}

The code works for submitting but the parent window always refresh
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.

I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.

Is there any way I can prevent it refreshing the page after click()?
Hi,

Did you put a target="nameofchildwindow" in the form on your parentpage?

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Reply With Quote
  #3  
Old   
SamuelXiao
 
Posts: n/a

Default Re: Click submit button without refresh - 11-03-2009 , 10:00 AM



On Nov 3, 10:42*pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
Quote:
SamuelXiao schreef:



Hi,

I am trying to submit a form in a parent window by using its child
window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
* *var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
* *window.opener.document.getElementById("btn1").cli ck();
* *window.close();
}

The code works for submitting but the parent window always refresh
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.

I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.

Is there any way I can prevent it refreshing the page after click()?

Hi,

Did you put a target="nameofchildwindow" in the form on your parentpage?

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
No, for calling child window in the parent, I use a function like the
following:

function mypopup()
{
mywindow = window.open ("xxx.jsp",
"mywindow","width=100,height=100");
mywindow.moveTo(0,0);
}

when click a button "popup";

Reply With Quote
  #4  
Old   
SAM
 
Posts: n/a

Default Re: Click submit button without refresh - 11-03-2009 , 10:03 AM



Le 11/3/09 3:14 PM, SamuelXiao a écrit :
Quote:
Hi,

I am trying to submit a form in a parent window
It's not exactly a "parent".

Quote:
by using its child window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
if(window.opener) {

Quote:
var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
window.opener.document.getElementById("input1").va lue = "hardcode";

Quote:
window.opener.document.getElementById("btn1").clic k();
window.close();
}

Quote:
}

The code works for submitting but the parent window always refresh
Normal, it's the default behavior.

In the parent :

<form id="form1" name="form1" target="other" action="mytest.php">

that will send the form in a new window (same window at each new try)

Notice: that way of doing is deprecated (If I'm not in error)

Quote:
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.
The form has it an ID ?
(and that id is named 'form1' ?)

Try :
document.forms['form1'].submit();
instead, if the form has only a name.

Quote:
I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.
You don't need a physical submit button when you do :
document.forms[0].submit()

Quote:
Is there any way I can prevent it refreshing the page after click()?
The file called by the action of the form must be send somewhere :
- in same window (default)
- a new window ( target="_blank" -or- target="noname" -or- JS function)
- a frame or iframe

Or you avoid the action :
<form onsubmit="return false;" blah... >
but it isn't your purpose, no ?


function submitOpenerForm(){
if(window.opener) {
var ope = window.opener.document.forms["form1"];
ope.elements["input1"].value = "hardcode";
ope.target = 'other';
ope.submit();
window.opener.focus(); // probably not useful
self.close();
}
else alert('Mother is closed');
}

--
sm

Reply With Quote
  #5  
Old   
SAM
 
Posts: n/a

Default Re: Click submit button without refresh - 11-03-2009 , 10:12 AM



Le 11/3/09 4:00 PM, SamuelXiao a écrit :
Quote:
On Nov 3, 10:42 pm, Erwin Moller
Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
SamuelXiao schreef:

Did you put a target="nameofchildwindow" in the form on your parentpage?

No, for calling child window in the parent, I use a function like the
following:
there is no importance the way you call your popup
(for the mother's form submitting)

It what asked if the form of the *opener* has an attribute 'target' !
Has it ?

Quote:
function mypopup()
{
mywindow = window.open ("xxx.jsp",
"mywindow","width=100,height=100");
mywindow.moveTo(0,0);
}

when click a button "popup";
function mypopup() {
if(typeof mywindow == undefined || mywindow.closed)
mywindow=window.open("xxx.jsp","mywindow","width=1 00,height=100,top=0,left=0");
mywindow.focus();
}

--
sm

Reply With Quote
  #6  
Old   
Hans-Georg Michna
 
Posts: n/a

Default Re: Click submit button without refresh - 11-03-2009 , 10:29 AM



On Tue, 03 Nov 2009 16:12:07 +0100, SAM wrote:

Quote:
if(typeof mywindow == undefined [...]
Small correction---I guess that should be:

if (typeof mywindow === "undefined" [...]

Hans-Georg

Reply With Quote
  #7  
Old   
Erwin Moller
 
Posts: n/a

Default Re: Click submit button without refresh - 11-03-2009 , 10:57 AM



SamuelXiao schreef:
Quote:
On Nov 3, 10:42 pm, Erwin Moller
Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
SamuelXiao schreef:



Hi,
I am trying to submit a form in a parent window by using its child
window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
window.opener.document.getElementById("btn1").clic k();
window.close();
}
The code works for submitting but the parent window always refresh
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.
I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.
Is there any way I can prevent it refreshing the page after click()?
Hi,

Did you put a target="nameofchildwindow" in the form on your parentpage?

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

No, for calling child window in the parent, I use a function like the
following:

function mypopup()
{
mywindow = window.open ("xxx.jsp",
"mywindow","width=100,height=100");
mywindow.moveTo(0,0);
}

when click a button "popup";
Hi,

As SAM wrote: That isn't important.
What is important is where the form should be posted.
If you don't give a target for the form, the form ALWAYS posts to the
window that contains that form.
If you want it to post somewhere else (or better formulated: "If you
want the response from the server-that-processes-the-form to appear
somewhere else") you SHOULD use target.
The value you give to target should be the name of that window/frame.

Mind you that using a target is a sin if you use strict doctype.

Regards,
Erwin Moller



--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Reply With Quote
  #8  
Old   
SamuelXiao
 
Posts: n/a

Default Re: Click submit button without refresh - 11-04-2009 , 07:30 AM



On Nov 3, 11:03*pm, SAM <stephanemoriaux.NoAd... (AT) wanadoo (DOT) fr.invalid>
wrote:
Quote:
Le 11/3/09 3:14 PM, SamuelXiao a écrit :

Hi,

I am trying to submit a form in a parent window

It's not exactly a "parent".

by using its child window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){

if(window.opener) {

* *var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";

window.opener.document.getElementById("input1").va lue = "hardcode";

* *window.opener.document.getElementById("btn1").cli ck();
* *window.close();

* * }

}

The code works for submitting but the parent window always refresh

Normal, it's the default behavior.

In the parent :

form id="form1" name="form1" target="other" action="mytest.php"

that will send the form in a new window (same window at each new try)

Notice: that way of doing is deprecated (If I'm not in error)

after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.

The form has it an ID ?
(and that id is named 'form1' ?)

Try :
* * document.forms['form1'].submit();
instead, if the form has only a name.

I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.

You don't need a physical submit button when you do :
* *document.forms[0].submit()

Is there any way I can prevent it refreshing the page after click()?

The file called by the action of the form must be send somewhere :
- in same window (default)
- a new window ( target="_blank" -or- target="noname" -or- JS function)
- a frame or iframe

Or you avoid the action :
* *<form onsubmit="return false;" blah...
but it isn't your purpose, no ?

function submitOpenerForm(){
* if(window.opener) {
* * *var ope = window.opener.document.forms["form1"];
* * *ope.elements["input1"].value = "hardcode";
* * *ope.target = 'other';
* * *ope.submit();
* * *window.opener.focus(); // probably not useful
* * *self.close();
* * *}
* else alert('Mother is closed');

}

--
sm
Actually, in my case, the opener window doesn't have a form element
(no <form>). For submitting data, it has buttonhandler (a javascript
function) for those button (submit button). So "target" is not able to
be used in the opener window's "form".

But the way, thanks for your idea, now I make a copy of the opener
window's input fields in the "child" window, set it in a form, then
submit by using target, but it will popup another window "other", then
close. Is there anyway not allowing a new window popup by
target="other"? I am not allowed to use iframe.

Reply With Quote
  #9  
Old   
SamuelXiao
 
Posts: n/a

Default Re: Click submit button without refresh - 11-04-2009 , 07:33 AM



On Nov 3, 11:57*pm, Erwin Moller
<Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
Quote:
SamuelXiao schreef:





On Nov 3, 10:42 pm, Erwin Moller
Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
SamuelXiao schreef:

Hi,
I am trying to submit a form in a parent window by using its child
window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
* *var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
* *window.opener.document.getElementById("btn1").cli ck();
* *window.close();
}
The code works for submitting but the parent window always refresh
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.
I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.
Is there any way I can prevent it refreshing the page after click()?
Hi,

Did you put a target="nameofchildwindow" in the form on your parentpage?

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

No, for calling child window in the parent, I use a function like the
following:

function mypopup()
*{
* * *mywindow = window.open ("xxx.jsp",
* * *"mywindow","width=100,height=100");
* * *mywindow.moveTo(0,0);
*}

when click a button "popup";

Hi,

As SAM wrote: That isn't important.

What is important is where the form should be posted.
If you don't give a target for the form, the form ALWAYS posts to the
window that contains that form.
If you want it to post somewhere else (or better formulated: "If you
want the response from the server-that-processes-the-form to appear
somewhere else") you SHOULD use target.
The value you give to target should be the name of that window/frame.

Mind you that using a target is a sin if you use strict doctype.

Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare- Hide quoted text -

- Show quoted text -
Hi, do you know how I can submit to a target that will not popup a new
window and not the current window? Iframe seems to be the solution,
but I am not allowed to use it.

Reply With Quote
  #10  
Old   
Erwin Moller
 
Posts: n/a

Default Re: Click submit button without refresh - 11-04-2009 , 08:14 AM



SamuelXiao schreef:
Quote:
On Nov 3, 11:57 pm, Erwin Moller
Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
SamuelXiao schreef:





On Nov 3, 10:42 pm, Erwin Moller
Since_humans_read_this_I_am_spammed_too_m... (AT) spamyourself (DOT) com> wrote:
SamuelXiao schreef:
Hi,
I am trying to submit a form in a parent window by using its child
window.
Given there are a parent window and a child window, child window has
code like this:
function submitOpenerForm(){
var ope = window.opener.document.getElementById("input1").va lue =
"hardcode";
window.opener.document.getElementById("btn1").clic k();
window.close();
}
The code works for submitting but the parent window always refresh
after that, my question is, how can it click the button, processing
the form submit, but the parent page will not refresh?
For some reason, I can't use window.opener.document.getElementById
('form1').sumbit() bla bla to submit that form.
I know Ajax can submit form without refresh the page, but it needs a
url, and those data, my case is that, I am not sure those data are (or
are from which fields,input,so on), but I do know there is an input
element needed to be assigned value and there is only a submit
button.
Is there any way I can prevent it refreshing the page after click()?
Hi,
Did you put a target="nameofchildwindow" in the form on your parentpage?
Regards,
Erwin Moller
--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare
No, for calling child window in the parent, I use a function like the
following:
function mypopup()
{
mywindow = window.open ("xxx.jsp",
"mywindow","width=100,height=100");
mywindow.moveTo(0,0);
}
when click a button "popup";
Hi,

As SAM wrote: That isn't important.

What is important is where the form should be posted.
If you don't give a target for the form, the form ALWAYS posts to the
window that contains that form.
If you want it to post somewhere else (or better formulated: "If you
want the response from the server-that-processes-the-form to appear
somewhere else") you SHOULD use target.
The value you give to target should be the name of that window/frame.

Mind you that using a target is a sin if you use strict doctype.

Regards,
Erwin Moller



Hi, do you know how I can submit to a target that will not popup a new
window and not the current window? Iframe seems to be the solution,
but I am not allowed to use it.
Hi,

A hidden frame maybe?
Make some frameset, make 1 window in there 0 pixels height, let the
other be your current window, and post to the hidden one.
It is an old solution.
That is how I communicated with a server without a pagereload in the
days before XMLHTTPrequest (AJAX). ;-)

In case you are not allowed to use frames/Iframes and no new windows, I
think you must use a XMLHTTPRequest.
If that is impossible too, well you'll have to resort to things like
Java-applets maybe.

What is it excatly you are trying to achieve?
Can't you simply use XMLHTTPRequest object instead?


Regards,
Erwin Moller

--
"There are two ways of constructing a software design: One way is to
make it so simple that there are obviously no deficiencies, and the
other way is to make it so complicated that there are no obvious
deficiencies. The first method is far more difficult."
-- C.A.R. Hoare

Reply With Quote
Reply




Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off



Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.