How does the form validation work on angularjs with ionic?

Javascript - Validation Field Colour Change

  • I currently have javascript validation set up on my form, (client side validation) it checks to ensure certain fields are filled in. I am looking for code that will also change the colour of the fields the script already validates if they are not compeleted. It will work with the validation script I have already, so coupled with the alert message that tells customers what fields they have missed I also want those fields to turn red say.

  • Answer:

    Hello nyoung-ga Without seeing the current coding of your page I will have to try to give you a generic answer, should you require any further help at integrating it into your site please ask for clarification and I will do my best to respond promptly. The easiest way to tackle this problem is to use style sheets. In the example below I have used the onFocus and onChange events to show you how to alter the color of a form element: <style>.changecolor {background: blue}.currentcolor {background:red}</style> <form> First Name: <input type="text" size="10" name="myname" onFocus="this.className='currentcolor'" onChange="this.className='changecolor'"><br> </form> Therefore in your script if the field is not filled in you simply need to change the color of the form elements using your existing "if the box is empty" statement. An example of this can be seen below: <style>.errorcolor {background: red}</style> <SCRIPT LANGUAGE="JavaScript"> <!-- function valid(form) { var field = form.myname; if (field.value=='') { alert("You must indicate your name."); field.className='errorcolor'; return false; } return true; } // --> </SCRIPT> <FORM METHOD="POST" onSubmit="return valid(this)"> Your name:<BR><INPUT TYPE="text" NAME="myname" /> <INPUT TYPE="submit" VALUE="Submit" /> </FORM> Once again, if you require any further help on this please ask for clarification and I will do my best to help quickly. If you do require further help it would be very helpful to see your current page code and javascript script. For further information there is an excellent article here that discusses something similar to what you are trying to achieve: http://www.xs4all.nl/~sbpoley/webmatters/formval.html

nyoung-ga at Google Answers Visit the source

Was this solution helpful to you?

Related Q & A:

Just Added Q & A:

Find solution

For every problem there is a solution! Proved by Solucija.

  • Got an issue and looking for advice?

  • Ask Solucija to search every corner of the Web for help.

  • Get workable solutions and helpful tips in a moment.

Just ask Solucija about an issue you face and immediately get a list of ready solutions, answers and tips from other Internet users. We always provide the most suitable and complete answer to your question at the top, along with a few good alternatives below.