Jump to content


Photo

php vs javascript


  • Please log in to reply
6 replies to this topic

#1 mistakes!

mistakes!
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 May 2006 - 04:03 PM

hello everyone,
i have gotthis code, it is actually a php file, but If there is an error I use JavaScript to give an alert message using alert box in java scripting.
pls can anyone me the advantages of using the javascrpt over just echoing the error using standard php.

all ideas will be really appreciated.

#2 ober

ober
  • Staff Alumni
  • Advanced Member
  • 5,337 posts
  • LocationEast Coast, USA

Posted 08 May 2006 - 05:45 PM

I'm not sure why you would ever want to use JavaScript to echo a PHP error message unless you want to do it with a pop-up. The preferred method is always going to be via PHP.

Info: PHP Manual


#3 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 08 May 2006 - 06:02 PM

Unless he means error messages which he may define in his script such as someone didn't fill in required field in a form. If you are dealing with forms then javascript is the best tool as you can get javascript to check whether the user filled in the required fields with the correct data and prevent the form from submitting if it does have errors.

#4 mistakes!

mistakes!
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 May 2006 - 08:07 PM


yeah thats what i mean i have used an alert box in java scripting i just wanted to find out the advantages of doing this instead of just echoing the msg with php.

thanks alot

#5 todd3834

todd3834
  • New Members
  • Pip
  • Newbie
  • 8 posts

Posted 08 May 2006 - 08:35 PM

[!--quoteo(post=372393:date=May 8 2006, 01:07 PM:name=mistakes!)--][div class=\'quotetop\']QUOTE(mistakes! @ May 8 2006, 01:07 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
yeah thats what i mean i have used an alert box in java scripting i just wanted to find out the advantages of doing this instead of just echoing the msg with php.

thanks alot
[/quote]

That all depends on preference. Depending on the design of your website, sometimes it may look/function nicer to have a javascript alert that gives the error message, sometimes it is better to use PHP. The advantage to using javascript to show errors is that you can create a function to validate your form with javascript and it can let the user know about any errors before they even submit the form. This could save time and save them from having to re-type anything. An advantage to using PHP would be you could create a custom msg box that simply shows up on the page where you want it and looks the way you want it. Ideally you will want to look into using AJAX for validating your forms in the future...

#6 mistakes!

mistakes!
  • Members
  • PipPip
  • Member
  • 12 posts

Posted 08 May 2006 - 09:56 PM

[!--quoteo(post=372399:date=May 8 2006, 03:35 PM:name=Surfer Bum)--][div class=\'quotetop\']QUOTE(Surfer Bum @ May 8 2006, 03:35 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
That all depends on preference. Depending on the design of your website, sometimes it may look/function nicer to have a javascript alert that gives the error message, sometimes it is better to use PHP. The advantage to using javascript to show errors is that you can create a function to validate your form with javascript and it can let the user know about any errors before they even submit the form. This could save time and save them from having to re-type anything. An advantage to using PHP would be you could create a custom msg box that simply shows up on the page where you want it and looks the way you want it. Ideally you will want to look into using AJAX for validating your forms in the future...
[/quote]

thanks alot it really helped!

#7 phporcaffeine

phporcaffeine
  • Members
  • PipPipPip
  • Advanced Member
  • 361 posts
  • LocationOhio, USA

Posted 08 May 2006 - 10:11 PM

[!--quoteo(post=372428:date=May 8 2006, 05:56 PM:name=mistakes!)--][div class=\'quotetop\']QUOTE(mistakes! @ May 8 2006, 05:56 PM) View Post[/div][div class=\'quotemain\'][!--quotec--]
thanks alot it really helped!
[/quote]


Keep in mind that if you echo php/mysql errors to the browser via JS then the text of that error is cached client side. It's no more a security risk than letting PHP echo the error to the window, just something you should be aware of.
Thanks,

Ryan Huff
President & Founder, MyCodeTree
support@mycodetree.com | http://mycodetree.com




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users