...

View Full Version : Apply Style to Textbox



jason_kelly
10-04-2011, 08:42 PM
Hello,

Using Javascript,

How would I go about apply the following code below as a style class (Error) to a single textbox?

Here's what I have so far:

document.getElementById('T1').style.backgroundColor = 'FEF6F4'
document.getElementById('T1').style.border = '1px solid #CD0A0A'


Thanks.

J

rangana
10-04-2011, 09:34 PM
A very basic one:


<style type="text/css">
.error {
background: #fef6f4;
border:1px solid #cd0a0a;
}
</style>
<script type="text/javascript">
function showErr(el) {
el.className = el.className=='error'?'':'error';
}
</script>
Try to clicking on the textbox for now<br>
<input type="text" onclick="showErr(this);">

Philip M
10-04-2011, 09:37 PM
<head>
<style type = "text/css">
.Error {background-color: #FEF6F4; border:1px solid #CD0A0A;}
</style>
</head>

<body>

<input type = "text" id = "T1">

<script type = "text/javascript">
document.getElementById("T1").className = "Error"
</script>
</body>

You might wish to make the background color more striking.


This year, if you want to win the Premiership, you are going to have to finish above Manchester United. - Commentator, Talksport

rangana
10-04-2011, 09:42 PM
Looks good Philip, except from the stylesheet:


<style type = "text/css">
.Error {backgroundColor = 'FEF6F4';border = '1px solid #CD0A0A'}
</style>


...should have been:


<style type = "text/css">
.Error {background-color = '#FEF6F4';border: 1px solid #CD0A0A;}
</style>

Philip M
10-04-2011, 09:49 PM
Looks good Philip, except from the stylesheet:


<style type = "text/css">
.Error {backgroundColor = 'FEF6F4';border = '1px solid #CD0A0A'}
</style>


...should have been:


<style type = "text/css">
.Error {background-color = '#FEF6F4';border: 1px solid #CD0A0A;}
</style>


Yes, I know Raymond. I corrected it already! :)

jason_kelly
10-05-2011, 06:40 PM
Works great and a great big thanks to everyone on here for their help!

You guys rock!

Take care

J



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum