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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How do I change parent <tr> bgcolor with onchange 2

Status
Not open for further replies.

LyndonOHRC

Programmer
Sep 8, 2005
603
0
0
US
I'm trying to change the background color of of a row that has column heading data for the rows below if data is changed in one of the input fields.

I have a second row with form fields in it and I have the ChangeParent function in the onchange event of some of the input fields. I'm trying to pass the id of the first row and can't seem to get the background color to change.

I hope I'm close, by reading similar posts, but can't get it to work...

Thanks

Code:
<tr id="Parent1">
 <td> column headings.....</td>
</tr>
<tr id="Child1">
  <td>
    Date:
  </td>
  <td>
   <input type=text name="startdate" size="10" onchange="ChangeParent('Parent1');">
  </td>
</tr>

<script language=javascript>

function ChangeParent(trid){
 var edited_row_bgcolor = '#FAEBD7';
 var elm = document.getElementById(trid);
 document.elm.style.background = edited_row_bgcolor;
}

</script>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
You are close, change this:

Code:
document.elm.style.background = edited_row_bgcolor
to this:

Code:
elm.style.backgroundColor = edited_row_bgcolor;

[monkey][snake] <.
 
You are close, change this:

Code:
document.elm.style.background = edited_row_bgcolor

To this:

Code:
elm.style.backgroundColor = edited_row_bgcolor;

[monkey][snake] <.
 
I'm now getting a javascript error: Object required. And no color change...

On this Line:
Code:
elm.style.backgroundColor = edited_row_bgcolor;

Complete Function:
Code:
function ChangeParent(trid){
		var edited_row_bgcolor = '#FAEBD7';
		var elm = document.getElementById(trid);
		elm.style.backgroundColor = edited_row_bgcolor;
	}


Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Make your onchange event handler an onblur handler instead.

Code:
<input type=text name="startdate" size="10" [!]onblur[/!]="ChangeParent('Parent1');">


I didn't pay total attention, you really can't define an onchange event in a textbox.

I did test this.

Another thing, make sure you have quotations around <input type=[!]text[/!].



[monkey][snake] <.
 
I didn't pay total attention, you really can't define an onchange event in a textbox.

That's not true, the event just isn't triggered until the box loses focus.

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
I'm still getting the same "Object required" error message.

I included all of my js functions just in case that affects something. Also, I copied the code from my view source in case I was not getting my variable data correct.

Thanks so much!

My exact code from view source:
Parent Row Created
Code:
<tr onclick="tableHideShow('1')" id="ParentRow1">
Form Input Created
Code:
<INPUT TYPE="Text" NAME="dteRec_Date1" ONBLUR="ChangeParent(ParentRow1);" CLASS="SmallForm" SIZE="10" MAXLENGTH="10" VALUE="01/05/2007">
Complete Script on this page
Code:
<script language=javascript>
	function tableHideShow(divid) {
		var elm=document.getElementById(divid);
		if (elm.style.display=="block")
			{
				elm.style.display='none';
			}
		else
			{
				elm.style.display='block';
			}
	}
	
	function ClearSearchForm(){
		document.SearchForm.ssn.value="";
		document.SearchForm.lname.value="";
		document.SearchForm.fname.value="";
		document.SearchForm.PreviousButton.disabled=true;
		document.SearchForm.NextButton.disabled=true;
		document.SearchForm.ssn.focus();
	}
	
	function ChangeParent(trid){
		var edited_row_bgcolor = "#FAEBD7";
		var elm = document.getElementById(trid);
		elm.style.backgroundColor = edited_row_bgcolor;
	}
</script>

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
-kaht

This is a great time for me to ask: "what triggers onblur". I'm trying to learn; maybe I'll retasin something someday. LOL

I had been making style changes using the onchange event but thought maybe calling a function from onchenge was the trouble???

Thanks!

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
I didn't pay total attention, you really can't define an onchange event in a textbox.

That's not true, the event just isn't triggered until the box loses focus.

I stand corrected.

However, it's not technically fired on an onchange, it's fired on an onblur.

[monkey][snake] <.
 
onblur is triggered when the element loses focus - but it's different from onchange because that's only triggered if something was changed when it loses focus.

For example, a textbox has the string "abc". You click on the textbox and then click something else, the onblur event is triggered.

However, if you click on the textbox, change the string to "abcd" and then click off the textbox, the onblur AND the onchange events are triggered.


The reason you're getting the object required message is because that HTML element cannot be found on the page. This means that your document.getElementById(whatever) is returning nothing. From looking at what you posted up above, I'm guessing it's because you didn't put any quotes around what I've highlighted in red:
Code:
<INPUT TYPE="Text" NAME="dteRec_Date1" ONBLUR="ChangeParent([!]ParentRow1[/!]);" CLASS="SmallForm" SIZE="10" MAXLENGTH="10" VALUE="01/05/2007">

-kaht

Looking for a puppy? [small](Silky Terriers are hypoallergenic dogs that make great indoor pets due to their lack of shedding and small size)[/small]
 
Then only onchange will help me.

Works great after I got the quotes in there correclty.

Thanks to you both!!!

Lyndon

---People Remember about 10% of what you say ---They never forget how you made them feel. Covey
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top