codenewbie3008
codenewbie3008

Reputation: 55

Javascript form AJAX styling

I'm using the following code to create a simple form. How do I make it so that when someone clicks in one of the input fields, the border changes colour? Thanks in advance

<style>
.texta {  
  color: #CDCBCB;  
  background-color: #FFFFFF;  
  border: 1px solid #E2E2E2;
  font-style:italic
}  

.sendbutton {
    background:#F6F6F6; color:#999999;
    border: 1px solid #E2E2E2;  
    cursor:pointer;
    padding:5px 10px;
    -webkit-border-radius:8px
}
</style>


<form action="mailto:[email protected]" method="post" enctype="text/plain">
<div style="height:12px;"><input type="text" name="name" value="Name (required)" size="40" class="texta"></div><br>
<div style="height:12px;"><input type="text" name="mail" value="Email (required)" size="40" class="texta"></div><br>
<div style="height:12px;"><input type="text" name="comment" value="Subject (required)" size="40" class="texta"></div><br>
<textarea name="Message" value="Message (required)" cols="40" rows="6" class="texta"></textarea><br>
<br><input type="submit" value="&nbsp; &nbsp; Send &nbsp;&nbsp;" class="sendbutton">
</form>

Upvotes: 0

Views: 185

Answers (2)

Julio Saito
Julio Saito

Reputation: 409

You can do by jQuery too. Just download jQuery (http://jquery.com/) and put this code in your .... But, I think the CSS solution is better.

<script>
    $("input:text")
    .focus(function(){
        $(this).css("border-color", "#F00");
    })
    .focusout(function(){
        $(this).css("border-color", "#333");
    });
</script>

Upvotes: 0

SLaks
SLaks

Reputation: 887449

Add a CSS rule for .texta:focus and set border-color.

Upvotes: 2

Related Questions