Jump to content

php vs javascript


mistakes!

Recommended Posts

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

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.
Link to comment
Share on other sites

[!--quoteo(post=372393:date=May 8 2006, 01:07 PM:name=mistakes!)--][div class=\'quotetop\']QUOTE(mistakes! @ May 8 2006, 01:07 PM) [snapback]372393[/snapback][/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...
Link to comment
Share on other sites

[!--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) [snapback]372399[/snapback][/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!
Link to comment
Share on other sites

[!--quoteo(post=372428:date=May 8 2006, 05:56 PM:name=mistakes!)--][div class=\'quotetop\']QUOTE(mistakes! @ May 8 2006, 05:56 PM) [snapback]372428[/snapback][/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.
Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.