Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

how to set the bordercolor of parent in js?

Status
Not open for further replies.

heeeep72

Programmer
Dec 15, 2004
33
CH
Hi,

i have an input field, it sits in a <td>, on certain conditions i want to set the border of the surrounding <td> to red from js. How to do it?
I tried these (without success):

1.)
Code:
inputField.parentNode.style.borderColor='#FF0000';//red

2.)
Code:
inputField.parentNode.className = 'redborder';//having a proper class defined in css 
...

//css:
TD.errorborder {
	border-style: solid;
	border-width: 3px;
	border-color: #FF00FF;
}

None of the above works for me!
Thx for any help!!
heeeep
 
Number 2 wouldn't work because you're setting the className to "redborder", but specifying "errorborder" in the CSS. Resolve this, and it should work.

Hope this helps,
Dan

Coedit Limited - Delivering standards compliant, accessible web solutions

[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Hi Dan,

that did not solve my problem, because that was just a "surface error": I had it right in my own code, I just made a "typing error", when I copied it into here (cause i changed some names)...

Probably both ways should be good and working, but the 1st one should be something like this:

Code:
		if (...blablabla...) {
			// Set the border red.
			inputField.parentNode.style.borderStyle = 'solid';
			inputField.parentNode.style.borderWidth = '1px';
			inputField.parentNode.style.borderColor = '#FF0000';// red
		} else {
			// Reset the border. 
			...blablabla...
		}

..so i set NOT just the color...(this is how it works in my code right now)

Two things could have caused the real problems:
-some css classes got garbled (is there an english word like this? :))) in my .css
-some other functions in my .js repainted the border, which i haven't noticed

...anyway, thanx for being helpful!!

heeeep
 
This works. I used a span as the inner node inside the TD.

Code:
<html>

<head>
<style>

TD.redborder {
    border-style: solid;
    border-width: 3px;
    border-color: #FF0060;
}

TD.greenborder {
    border-style: solid;
    border-width: 3px;
    border-color: #00FF00;
}

</style>

<script language="javascript">

function makeItNicer(pElem, pCSSname)  {

    pElem.parentNode.className = pCSSname ;  //having a proper class defined in css 
}

</script>

<body>

<table border=2>
<tr><td> One  </td><td>

<span onclick="makeItNicer(this, 'redborder')">Two - Make My Border Red</span>

</td><td> Three  </td></tr>
<tr><td> Four  </td><td>

<span onclick="makeItNicer(this, 'greenborder')">Five - Make My Border Green</span>

</td><td> Six  </td></tr>
</table>

</body></html>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top