Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 4 of 4
  1. #1
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts

    how to put a border around an input box

    how do i put a red border around an input box with a class of .input1 if it goes into this loop??


    Code:
    	if(firstName=='' || firstName.length < 3 || firstName=='First Name:' ){
    				error = 'Please enter your first name';
    				$j('#errormsg').html('<p class="errors">'+ error +'</p>');
    		
    				return false;
    			}

  • #2
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts
    Not really a JS problem.
    Code:
    <input type="text" style="border:3px dotted red" value="">
    Change the CSS style to match your needs.

  • #3
    Regular Coder
    Join Date
    Jun 2009
    Posts
    351
    Thanks
    75
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by jmrker View Post
    Not really a JS problem.
    Code:
    <input type="text" style="border:3px dotted red" value="">
    Change the CSS style to match your needs.
    yes but i only want it to change when it goes into the if statement.

  • #4
    Senior Coder jmrker's Avatar
    Join Date
    Aug 2006
    Location
    FL
    Posts
    3,091
    Thanks
    38
    Thanked 498 Times in 492 Posts

    Lightbulb

    Have not see the rest of your code, so this is just a snippit guess as to what you are trying to do.
    Code:
    <!DOC HTML>
    <html>
    <head>
    <title> Untitled </title>
    <style type="text/css">
      .err  { border:3px dotted red; }
      .OK { border:1px solid black; }
    </style>
    
    <script type="text/javascript">
    function checkInput() {
      var sel = document.getElementById('firstName');
      if ( (sel.value=="") || (sel.value.length <3) || (sel.value=='First Name:') ) {
        sel.className = 'err';  alert('Entry error'); 
      } else {
        sel.className = 'OK';
      }
    }
    </script>
    
    </head>
    <body>
    <form onsubmit="return false">
    <input id="firstName" type="text" class='OK' value="First Name:">
    <button onclick="checkInput()">Check</button>
    </form>
    </body>
    </html>
    Additional logic could be used to clear input after entry errors!


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •