Joseph Witchard Posted November 27, 2008 Share Posted November 27, 2008 JavaScript: function goBold() { var goBoldButton = prompt("Please enter the text that is to be bold", ""); var boldText = "" + goBoldButton + ""; document.newsForm.newsBody.value += boldText; } function goItalic() { var goItalicButton = prompt("Please enter the text that is to be italic", ""); var italicText = "" + goItalicButton + ""; document.newsForm.newsBody.value += italicText; } function errorCheck() { var body = document.newsForm.newsBody.value; var title = document.newsForm.newsTitle.value; // check to see that the information is valid if (body == "" || body == "NULL") { alert("Please enter some news!"); return false; } else if (title == "" || title == "NULL") { alert("Please enter a news title!"); return false; } else { return true; } HTML Form: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <title>Rebirth Administration News Center</title> <meta http-equiv="content-type" content="text/html; charset=utf-8"> <meta http-equiv="cache-control" content="no-cache"> <link href="/css/general2.css" rel="stylesheet" type="text/css"> <script language="javascript" type="text/javascript" src="/javascripts/aaNews.js"></script> </head> <body> <div align="center" style="text-align: center;"> <h2>News Form</h2> <form id="newsForm" name="newsForm" method="post" action="https://uhrebirth.com/staff/lets_go.php" onSubmit="return errorCheck();"> <label for="newsTitle">Title:</label> <input type="text" id="newsTitle" name="newsTitle" size="30"> <br> <br> <label for="newsType">Category:</label> <select id="newsType" name="newsType"> <!-- SERVER SIDE CODE GOES HERE --> </select> <br> <br> <label for="newsBody">Body:</label> <br> <textarea id="newsBody" name="newsBody" style="width: 500px; height: 200px; overflow: auto;"></textarea> <br> <br> <input type="button" value="BOLD" onClick="goBold();"> <input type="button" value="ITALIC" onClick="goItalic();"> <br> <br> <input type="submit" id="submit" name="submit" value="Submit News"> <input type="reset" value="Reset"> </form> </div> </body> </html> I swear JavaScript hates me. Could someone explain to me why this isn't working? The JavaScript doesn't do anything when you press the bold and italic buttons, and it does nothing when you submit the form with the wrong data. NOTE: If the bold and italic JavaScript functions show empty quotes, that's because BBCode goes there. Quote Link to comment Share on other sites More sharing options...
divinequran Posted December 1, 2008 Share Posted December 1, 2008 the error may be due to the function errorCheck() which is not closed properly, you have opened the brace for the function ({) but you have not closed it with(}) Quote Link to comment Share on other sites More sharing options...
Joseph Witchard Posted December 6, 2008 Author Share Posted December 6, 2008 That did it. Thanks 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.