Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Calling a JavaScript function on a different HTML page from a PHP file?
Old 10-27-2006, 12:02 PM Calling a JavaScript function on a different HTML page from a PHP file?
FOOOD's Avatar
Average Talker

Posts: 25
Name: Jono
Trades: 0
I have contact form on a HTML page called contact.html

Once someone has filled out their details, typed their message & clicked on 'Send' it goes to a PHP file 'contact/contactform.php'

If the message is sent successfully the contactform.php will then redirect to thanks.html (which basically says 'Thanks, your message has been sent etc.')
Or if the message wasn't sent successfully the contactform.php will redirect to error.html (Sorry, there was an error. Your message hasn't been sent etc.')

What I'd like to is instead of contactform.php redirecting to thanks.html or error.html I'd like to call some JavaScript functions back in the contact.html page


Code:
<script type="text/javascript">
function doThanks() {
Effect.Appear('send',{duration:1.0}), Effect.SlideDown('send',{duration:1.0});
return false;
}
</script>
if the message is sent successfully.



Code:
<script type="text/javascript">
function doError() {
Effect.Appear('send',{duration:1.0}), Effect.SlideDown('send',{duration:1.0});
return false;
}
</script>
If the message isn't sent successfully.



Here is the code in the PHP file that redirects to the thanks.html or error.html pages

Code:
// redirect to success page
if ($success){
  print "<meta http-equiv=\"refresh\" content=\"0;URL=thanks.html\">";
}
else{
  print "<meta http-equiv=\"refresh\" content=\"0;URL=error.html\">";
}

Is this possible, & if so how?

Last edited by FOOOD; 10-27-2006 at 01:55 PM..
FOOOD is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 10-28-2006, 12:25 AM Re: Calling a JavaScript function on a different HTML page from a PHP file?
funkdaddu's Avatar
Web Design Snob

Posts: 635
Trades: 0
You would make an AJAX-style XMLHTTPRequest call to the php file, the php file would return a fail/success code to the script, then you would process it. THis is pretty much what you are looking for right: http://www.dustindiaz.com/ajax-contact-form/
He has the code free on his site, so d/l it and see if it would work for you.
funkdaddu is offline
Reply With Quote
View Public Profile Visit funkdaddu's homepage!
 
Old 10-28-2006, 06:53 PM Re: Calling a JavaScript function on a different HTML page from a PHP file?
FOOOD's Avatar
Average Talker

Posts: 25
Name: Jono
Trades: 0
Thanks, I took a look at it but it looks a little beyond me to figure out
I guess there isn't a simpler way to call the JavaScript funtion on 1 page from another page?

You can see the effect that would happen here http://www.iconaholic.com/contact2.html

To see the effect clicking on 'Test - Thanks message' (bottom of the page) shows you what would happen if you filled out the form, clicked on Send & the message was sent successfully. Clicking on 'Test - Error message' shows you what would happen if you filled out the form, clicked on Send & the message wasn't sent successfully.

If it was simpler I could leave the PHP file to redirect to the thanks.html page, & then call the JavaScript function on the contact.html page from there (rather than calling the JavaScript function from the PHP page).
FOOOD is offline
Reply With Quote
View Public Profile
 
Old 11-01-2006, 02:02 PM Re: Calling a JavaScript function on a different HTML page from a PHP file?
Banned

Posts: 61
Name: Oh, don't go there
Location: United States
Trades: 0
If you get the javascript, then I will include it into your script...Otherwise no time atm, sorry.
Frostydasnowman is offline
Reply With Quote
View Public Profile Visit Frostydasnowman's homepage!
 
Reply     « Reply to Calling a JavaScript function on a different HTML page from a PHP file?
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

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

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.24775 seconds with 12 queries