Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Location.reload trouble, please help

Status
Not open for further replies.

Guest_imported

New member
Jan 1, 1970
0
0
0
OK I have a major problem here.
function submitAndRefresh() {
if(document.myForm.elements[0].value == "" ||
document.myForm.elements[1].value == "" ||
document.myForm.elements[2].value == "")
{ alert("Empty Fields");
}
else {
document.updateForm.submit();
refreshPage( );

}
}
function refreshPage( ) {
parent.topFrame.location.reload();
}


OK this works most of the time but occasionally, about every 5 goes ( this varies ) it refreshes before the form is submitted. I'm not using a submit button but a regular button with an onclick event.

<input type=&quot;button&quot; id=&quot;btnSub&quot; name=&quot;btnSub&quot; value=&quot;Submit&quot; onClick=&quot;submitAndRefresh();&quot;>

I need your help
 
do not use a button to call validation/submit function !!!!!!!
do this instead :
* call the function ONSUBMIT
<form ..... onSubmit=&quot;return submitAndRefresh()&quot;>
* do not forget the RETURN
* make the function return a boolean : true if you want the form submitted, false if not

function submitAndRefresh() {
if(....)
{ alert(&quot;Empty Fields&quot;);
return false
}
else {
document.updateForm.submit();
return true
}
}
--> this will submit the form if and only if the conditions are ok

now, you want to refresh AFTER submitting right ?

<form ..... onSubmit=&quot;return submitAndRefresh(); refreshPage()&quot;>
------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
i'm sooooooooooooooooooooooorry !!!
there is an error here :

function submitAndRefresh() {
if(....)
...
else
return true

}
}

you don't have to submit yourself, as returning true means exactly document.updateForm.submit() !!
------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
I need more help, Everything you did worked fine except for the refreshing. The form gets submitted properly, but the call to the refresh function gets ignored.

<form name=&quot;updateForm&quot; method=&quot;post&quot; action=&quot;processForm.asp&quot; onSubmit=&quot;return submitAndRefresh(); refreshPage()&quot;


 
and if you let the call to refreshPage() in the function (it has to be BEFORE the return line or else it'll never be read - that's why it's not executed in the onsubmit : my fault !) it'll refresh BEFORE the page is submitted, not 1 time out of 5 but all the times !!! so i think your 1st idea was the good one (sorry i'm tired today !!!) and the refresh will randomly break your page ...
no ! there IS to be a solution !
why are you reloading the page ? i mean, the page should be replaced with &quot;processForm.asp&quot; right ? or is it a frame ?
------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
I have two frames, the top one contains a table populated by a database.
On the bottom frame I have a form that changes the value of one of these rows in the table. So I want to refresh after the submit. Processform.asp just does some basic checks and stuff. This has to be in a seperate page.
 
ok ! when you submit, (tell me if i'm wrong here !!), processform.asp loads into the top frame to display a new table (i have to be wrong or else your form tag would be : <form .... target=&quot;upper_frame_name&quot;>)
then the best way should be to call refresh from processform.asp
say the top frame is named &quot;table&quot; and the bottom one &quot;form&quot;
from &quot;table&quot;, call top.form.reload(true)
from &quot;form&quot;, call this.reload(true)
from an outside page, call form.reload(true)

------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
I hope I can explain what's happening better here.

When the page is loaded, an sql query is used to generate a table in the top frame of the page.
The bottom frame contains a form. Each of the table entries is a link, which runs a javascript function. This function pulls the values from that particular table entry and populates the textfields in the form. The user can then edit the data in the form, and click submit. The information is posted to processForm.asp, which updates the entries in the database. I want to refresh the top frame so that a new table is generated showing the updated information from the database.
I can do all of the above except the refreshing. This must happen after the form is submitted.
 
i see ... sorry for my misunderstanding !!!
there is no event such as onaftersubmit ... that's why it's easier if you can put some code inside the called page, because when it loads you're sure the submit has been done !
so - let your function it is good - all i can think of is to put a button in the upper frame, for the cases it has not been updated ------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
One other thing I don't suppose you know if there is anyway to prevent a page being cached so that when process form is finished and I redirect it to the update page it is forced to reload it. I know it's something like no cache, but where do I put it.
 
&quot;why does it work sometimes and not others &quot;
--> i think it depends on how fast is the form submitted - i mean, onsubmit fires before the actual submitting of the form, as onclick :(

&quot;anyway to prevent a page beeing cached&quot;
--> yes there are, but unfortunatly the search is down here for maintenance - as soon as it is back, you'll find plenty of threads on &quot;how to prevent files from beeing cached&quot;
what i remember from those threads
* you can use the meta tag : <META HTTP-EQUIV=&quot;PRAGMA&quot; CONTENT=&quot;NO-CACHE&quot;> - read this : coz there is a small bug with asp and maybe you need to write it twice in the page
* you can also append a random number or a date-time stamp to the name of your page - then the browsers will think it's a new page each time and won't look in their caches



------
please review FAQ183-874 - this will help you to get the best out of tt
[ &quot;you&quot; is not someone in particular - don't take it too personnal ]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top