1 Replies - 6188 Views - Last Post: 20 May 2011 - 04:44 AM

#1 drayarms  Icon User is offline

  • D.I.C Head

Reputation: 4
  • View blog
  • Posts: 178
  • Joined: 18-May 11

Can CSS styles be applied to form input text?

Posted 20 May 2011 - 04:30 AM

I downloaded this simple form which uses JS to limit the number of characters entered into the text input field by counting down from the maximum allowable number of characters (55) down to 0 as characters are being entered. I want to change the number being displayed from the default black to red. How can this be achieved? Anyone?


<form name="mymind" style= "position:relative;left:40px;" action="insert_status.php" method="post">

					<input  name="limitedtextfield" type="text" onkeydown="limitText(this.form.limitedtextfield,this.form.countdown,55);" 

					onkeyup="limitText(this.form.limitedtextfield,this.form.countdown,55);" maxlength="55"><br>

					<font size="1">(Maximum characters: 55)<br>

					You have <input readonly type="text" name="countdown" size="3" value="55"> characters left.</font>

					<input type="hidden" name="submitted" value="TRUE"/>

					<input style="position:relative;left:0px;bottom:0px;" type="submit" name="submit" value="Submit!" />

					</form>



<script language="javascript" type="text/javascript">
function limitText(limitField, limitCount, limitNum) {
	if (limitField.value.length > limitNum) {
		limitField.value = limitField.value.substring(0, limitNum);
	} else {
		limitCount.value = limitNum - limitField.value.length;
	}
}
</script>


This post has been edited by Dormilich: 20 May 2011 - 04:48 AM
Reason for edit:: moved the JS code in the OP


Is This A Good Question/Topic? 0
  • +

Replies To: Can CSS styles be applied to form input text?

#2 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3554
  • View blog
  • Posts: 10,335
  • Joined: 08-June 10

Re: Can CSS styles be applied to form input text?

Posted 20 May 2011 - 04:44 AM

you are aware that the maxlength attribute pretty much does the same? (without the eye-candy, though)

for the color problem, give the output element an id and use that to change its CSS property color to red.

This post has been edited by Dormilich: 20 May 2011 - 04:46 AM

Was This Post Helpful? 0
  • +
  • -

Page 1 of 1