Jason28 Posted September 4, 2008 Share Posted September 4, 2008 Hello, I searched Google on how to change the border color of a form field to red when there is an error and even though I found some examples I couldn't find a way to integrate it with my current javascript code. Here is my working error validation code: function checkme_station() { if (document.getElementById('station_name').value == "") { alert("Please enter a name for this station."); document.getElementById('station_name').focus();return(false) } if (document.getElementById('selection').value == "Enter song or musician name" || document.getElementById('selection').value == "") { alert("Please enter the name of the song or name of musician into selection field."); document.getElementById('selection').focus();return(false) } } Could you please edit this code so that the form fields have a red border when one of those errors are found? Thanks! Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 4, 2008 Share Posted September 4, 2008 function checkme_station() { stationObj = document.getElementById('station_name'); if (stationObj.value == "") { stationObj.style.borderColor = '#ff0000'; alert("Please enter a name for this station."); stationObj.focus(); return false; } selectionObj = document.getElementById('selection'); if (selectionObj.value == "Enter song or musician name" || selectionObj.value == "") { selectionObj.style.borderColor = '#ff0000'; alert("Please enter the name of the song or name of musician into selection field."); selectionObj.focus(); return false; } stationObj.style.borderColor = ''; selectionObj.style.borderColor = ''; return true; } Quote Link to comment Share on other sites More sharing options...
Jason28 Posted September 4, 2008 Author Share Posted September 4, 2008 Excellent thanks a lot Would it be hard to also make the text on the page red as well? I know that I have to assign a span class to that text but I need the javascript to do it. Thanks! Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 5, 2008 Share Posted September 5, 2008 What text? I'm assuming you don't meant the text in the input field since 2/3 of the validation is for when there is no text. So, I am guessing you are talking about the label. yes, that can be done, but if you make your FULL request up front it is more conducive to receiving the best response. Depending on how your labels and fields are constructed I might do things different than what I did above. please post the code for your form and I can assist. Quote Link to comment Share on other sites More sharing options...
Jason28 Posted September 5, 2008 Author Share Posted September 5, 2008 Thanks again and yes I am referring to the text before the input field on the html page. Actually could you take my original code that I posted and only add the javascript code to make the text turn red? The input fields look pink in firefox and a bright red in IE so I may just make the text red only. Thanks! Quote Link to comment Share on other sites More sharing options...
Psycho Posted September 5, 2008 Share Posted September 5, 2008 Actually could you take my original code that I posted and only add the javascript code to make the text turn red? How can I do that? You have not provided any sample of the HTML code. please post the code for your form and I can assist. 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.