How to clear the border color (preserving the existing one)

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

How to clear the border color (preserving the existing one)

Post by PHPycho »

Hello Forums !!
I had following script for marking the fields with certain color border and clearing that color border , preserving the fields original border color.

Code: Select all

<!-- Javascript -->
<script language="javascript">
function FMark(){
	document.forms['frm_mark'].test_field.style.border = "1px solid #ff0000";  
}

function FClear(){
	document.forms['frm_mark'].test_field.style.border = "none"; 
}
</script>

Code: Select all

<!-- HTML -->
<form name="frm_mark" action="#" method="get">
<input type="text" name="test_field" style="border: 1px solid #0066FF" />
<input type="button" value="Mark" onclick="FMark();"/>
<input type="button" value="Clear" onclick="FClear();"/>
</form>
Whats my problem ?
- I am able to mark the field but also able to clear that marked one but couldnt preserve the existing border color

What I want ?
- I want to clear the marked border color preserving the existing border color ie #0066FF
Any Suggestion and Help are warmly welcome
Thanks in advance to all of you
User avatar
PHPycho
Forum Contributor
Posts: 336
Joined: Fri Jan 06, 2006 12:37 pm

Post by PHPycho »

Thanks everbody ..
I got the solution:

Code: Select all

function FClear(){
	document.forms['frm_mark'].elements['test_field'].style.border = ""; 
}
Note: just keep the border style to blank

I would love to know if there are other alternatives
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Blank or "0" both work.
Post Reply