mistakes! Posted May 8, 2006 Share Posted May 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
ober Posted May 8, 2006 Share Posted May 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
wildteen88 Posted May 8, 2006 Share Posted May 8, 2006 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. Quote Link to comment Share on other sites More sharing options...
mistakes! Posted May 8, 2006 Author Share Posted May 8, 2006 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 Link to comment Share on other sites More sharing options...
todd3834 Posted May 8, 2006 Share Posted May 8, 2006 [!--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... Quote Link to comment Share on other sites More sharing options...
mistakes! Posted May 8, 2006 Author Share Posted May 8, 2006 [!--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! Quote Link to comment Share on other sites More sharing options...
phporcaffeine Posted May 8, 2006 Share Posted May 8, 2006 [!--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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.