Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <!--------Video Link--------->
- <!--https://www.youtube.com/watch?v=GMzszNc-xuI&index=2&list=PLFmBk1phabmF_gAOuhq6AI6Zn-iSmFe9x-->
- <!-------------HTML------------->
- <div class="form-group">
- <label for="name" class="col-sm-2 col-lg-2 control-label">Name:</label>
- <div class="col-sm-10 col-lg-5" id="name_div">
- <input type="text" class="form-control" id="name" placeholder="Full Name" onblur="CheckEmpty('name')"/>
- </div>
- </div>
- <!-----Modified Javascript function------>
- <script>
- function CheckEmpty(field_id){
- //
- var MyValue = document.getElementById(field_id);
- if(MyValue.value == "" || MyValue.value == null){
- //code
- displayWarning(field_id, MyValue.parentNode.id, "You can't leave this empty.");
- }
- }
- </script>
- <!--------New Javascript Code--------->
- <script>
- //function displays the error message
- function displayWarning(field_id, parent_div, message){
- var para = document.createElement("p");
- var error_msg = document.createTextNode(message);
- para.appendChild(error_msg);
- document.getElementById(parent_div).appendChild(para);
- }
- </script>
Advertisement
Add Comment
Please, Sign In to add comment