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!

Javascript HTMLObjectElement?

Status
Not open for further replies.

HollyVally

Programmer
Jan 3, 2003
48
0
0
BD
Hi all,

I am trying to write js functions without any success --- obviously that clearly shows my intelectual ability in js :-(

However, a job has to be done. Therefore these stupid questions.... ::::

While I was trying a function writen in-line it seems to work, and as I was trying to put these functions in .js include file. I managed to make a delicious mess !!!!!
Only the alert function works(lucky me!). Therefore, I managed (again my forefathers great luck was passing by!!) to see the passed parameter thru the alert func. Here is what I have got:

When I pass a 'form' as a parameter to a function it shows me that *martian creature* '[Object HTMLInputElement]' : FINE.

How do I handle that?

Can anybody be generous enough to help/guide me thru this *horrondous* journey of my great lesson in dear js?

Thanks a Zillion for at least reading this.
 
how r u passing the form into the function in the js file, ie 'this.form' or 'form' or 'document.form[0]' etc?
 
In my .js I have a function like:

Code:
function setClickedCell(myForm, cell)
{	
	var cellname = myForm.chosenCell.value; 
	if ( cellname ) 
	{
		myForm[cellname].style.backgroundColor = '#FEFA00';
	}
	myForm.cell.style.backgroundColor = '#FF0000';
	myForm.chosenCell.value = cell.value; // [b]this is the line i need the most[/b]
	return true;	
}
....... which I call from inside a table (* created on the fly by PHP *) like this:
Code:
<TD border=&quot;0&quot;>
	<INPUT	name=&quot;cell15&quot; 
			type=&quot;text&quot; 
			class=&quot;number&quot; 
			border=&quot;0&quot;
			value=&quot;&quot; 
			style=&quot;cursor:pointer;&quot; 
			onClick=&quot;setClickedCell(document.formCN, cell15); return;&quot; 
			readonly=true >
</TD>
[code]

I am certain that I have done something *horribly* wrong (thanks to my unconciousness of the js world :  but I wanna get into this!)

However I have tried the following(also using PHP to create it on the fly) :

[code]
<TD border=&quot;0&quot;>
	<INPUT	name=&quot;cell15&quot; 
			type=&quot;text&quot; 
			class=&quot;number&quot; 
			border=&quot;0&quot;
			value=&quot;&quot; 
			style=&quot;cursor:pointer;&quot; 
			onClick=&quot;javascript: {	
									var cellname = document.formCN.chosenCell.value; 
									if ( cellname ) 
									{
										// document.formCN.cellname.style.backgroundColor = '#FEFA00'; // doesnt work, no clue why?
										document.formCN[cellname].style.backgroundColor = '#FEFA00';
									}
									document.formCN.cell15.style.backgroundColor = '#FF0000';
									document.formCN.chosenCell.value =  document.formCN.cell15.value; // [b]this is the line i need most[/b]
									return true;	
								}&quot; 
			readonly=true >
</TD>
[code]

........... does work!(**surprisingly for me !**). But...............

I have quite a number of cells to serve with the similar function which makes big difference in overall download time. Hence my trial with the wide world of js.
PLease show me a work round of this or at least how can I convert this to a working js function!

Thank again folks.
 
i don't see where you're defining &quot;chosenCell&quot;



=========================================================
try { succeed(); } catch(E) { tryAgain(); }
-jeff
 
chosenCell is a hidden input box where I kepp this info only.
It is in the same form though.
 
try changing name=&quot;cell15&quot; to id=&quot;cell15&quot;


or in your function change to

myForm.chosenCell.value = myForm.cell.value

if the background colour of the text box is changing but the value is not being assigned then the above statement should sort it out
 
Any suggestion on the following:

using 'obj = document.getElementByID(ID);'

then can I change the obj.value or obj.name etc. inside the function to put effect in the calling document ?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top