Forum Moderators: open
function FClear(){
document.forms['frm_mark'].test_field.style.border = "none";
}
</script>
<!-- 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
So, instead of:
function FMark(){
document.forms['frm_mark'].test_field.style.border = "1px solid #ff0000";
}function FClear(){
document.forms['frm_mark'].test_field.style.border = "none";
}
Do this:
function FMark(){
document.forms['frm_mark'].test_field.style.border = "1px solid #ff0000";
}function FClear(){
document.forms['frm_mark'].test_field.style.border = "1px solid #0066FF";
}
Or even better:
function FMark(){
document.forms['frm_mark'].test_field.style.borderColor = "#ff0000";
}function FClear(){
document.forms['frm_mark'].test_field.style.borderColor = "#0066FF";
}
Either have a global object/array that holds the original colour of each element, or store the original colour on the element itself, as part of the ID or something? It may be possible to read the original colour from the element and build the 'original colour array' automatically, without having to directly code it.
define both borders under different classes in your stylesheet. Then, instead of changing the border color on the object, change the 'className' attribute
such as...
<style>
.classA {border:1px solid #ff0000;}
.classB {border:1px solid #0066FF;}
</style>
<script language="javascript">
function FMark(){
document.forms['frm_mark'].test_field.className = "classA";
}
function FClear(){
document.forms['frm_mark'].test_field.className = "classB";
}
<form name="frm_mark" action="#" method="get">
<input type="text" name="test_field" class="classB" />
this approach will give you the ability to edit your css file without changing all your html docs.
[edited by: Drag_Racer at 4:50 am (utc) on July 17, 2007]