jon4433 Posted February 19, 2012 Share Posted February 19, 2012 I have some if statements in my php code, and I would like to have javascript so that I can have pop up boxes with the error on. I have been trying to work it out, but i'm getting 2 errors. It's my first time using javascript today, so I have no idea if it is correct or not. My javascript and php if statement is giving me one error. <script type="text/javascript"> if(empty($username)) { function show_alert() { alert("Please fill in the username field!"); } } </script> And i'm also getting another error with the 'style type'. <style type="text/css"> body { font-family: Minecraft; background-image: url(images/background.png); background-size:100% 100%; background-attachment: fixed; background-repeat: repeat-x; background-position: left top; background-color: #999999; } body,td,th { color: #FFF; } </style> Link to comment https://forums.phpfreaks.com/topic/257299-javascript-in-php/ Share on other sites More sharing options...
trq Posted February 19, 2012 Share Posted February 19, 2012 PHP and JavaScript are not interchangeable. Your code makes litte sense. Link to comment https://forums.phpfreaks.com/topic/257299-javascript-in-php/#findComment-1318877 Share on other sites More sharing options...
jon4433 Posted February 19, 2012 Author Share Posted February 19, 2012 I learned the script from this website http://www.w3schools.com/js/js_popup.asp. I was trying to get it so, when a user leaves a blank box in my form, a popup window pops up and says a message to them. Link to comment https://forums.phpfreaks.com/topic/257299-javascript-in-php/#findComment-1318881 Share on other sites More sharing options...
trq Posted February 19, 2012 Share Posted February 19, 2012 That still doesn't change the fact that JavaScript and PHP are tow different languages that run in two completely different contexts. JavaScript executes client side within a browser, PHP executes server side within the server. Your code makes no sense because it attempts to mix the two together. Link to comment https://forums.phpfreaks.com/topic/257299-javascript-in-php/#findComment-1318882 Share on other sites More sharing options...
jon4433 Posted February 19, 2012 Author Share Posted February 19, 2012 I decided to do something else. Thank you anyway! Link to comment https://forums.phpfreaks.com/topic/257299-javascript-in-php/#findComment-1318885 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.