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!

Passing Objects To Functions

Status
Not open for further replies.

SimonMarkDawson

Programmer
Oct 17, 2001
23
0
0
GB
Hello

Hopefully a simple one for you experts!

I want to use the 'onclick' event of one object to pass a different object (A 'hidden' variable in this case) to a javascript function. I then want the javascript function to change the value property of the hidden variable.

I obviously can't use 'this' in the onclick event so presume it's something to do with [] brackets. So far I've tried permutations along the lines of:

function hdnch(a){
document.form1[a].value='1';
}

called within form1 by

$temp='A'
<input type='hidden' name=$temp value='0'>
<table ... ><tr>
<td onclick=hdnch($temp)... etc>

but to no avail. Could the problem be in my attempt to use the $temp variable as an object handle? Unfortunately this is necessary as I can't assign names to all the hidden fields (within a loop) directly because of the complexity of the (LONG) form.

Am I a hopeless case and should I take up gardening instead?! Please help!

Many Thanks,

- Simon
 
This works :

<script language=&quot;JavaScript&quot; type=&quot;text/JavaScript&quot;>
<!--
function hdnch(field){
document.form1[field].value='1';
}
//-->
</script>

<form name=&quot;form1&quot;>
<input type='hidden' name='$temp' value='0'>
<table>
<tr>
<td onclick=&quot;hdnch('$temp')&quot;>foo <input type=&quot;submit&quot;></td>
</tr>
</table>
</form>

notice the quotes

if you were using : this then you wouldn't need quotes Regards

Big Bad Dave

logo.gif


davidbyng@hotmail.com
 
The
Code:
setTimeout
function is one of the most disappointing things there is about Internet Explorer. Starting in Netscape 4, you could have
Code:
setTimeout
call a function (e.g.,
Code:
setTimeout(myFunct, myTimeout)
). Along with this came the ability to call functions in this manner came the ability to pass parameters to them (of course). This syntax would work fine:
Code:
setTimeout(myFunct, myTimeout, arg1, arg2, arg3)


HOWEVER, This functionality wasn't put into Internet Explorer. They gave the ability to call a function, but they did NOT provide the ability to pass parameters to it. The third parameter is what language the code is executed in, and the third is the last parameter it accepts.

This is why, whenever you see a function that you want to pass parameters to, you see a mangle of string concatenation... Causing you to want simply to make a global variable and call it instead of going through the hassle of passing parameters.

This is one out of two (only two, but a very special two) disappointments of IE that make me scream at the top of my lungs and take stabs at my computer. The inventors of IE surely did not believe in object orientation.
Code:
- UNIMENT
 
Hi

Thanks for the help Dave and Uniment. The first solution worked well - a question of missing &quot;'&quot; ' s in my script.

Anyway, thanks v much for your time and prompt responses.

- Simon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top