Click to See Complete Forum and Search --> : reference value of hidden input in form


roo141
02-13-2004, 10:46 AM
Hi

I'm trying to change the value of a hidden input field in a form when another button is clicked.

Something like,

<html>

<head>
<script type=Javascript>
function updateValue()
{ document.all.test.blah.value = 2;
}

</script>
</head>

<body>
<form name=test>

<INPUT name=blah type=text value=0>

</form>

<img src=em.gif onCLick=updateValue()>

</body>

</html>

I knew how to do this once but just can't remember what the proper way to reference it through the document is.

Any help is much appreciated.

Thanks

jaegernaut
02-13-2004, 11:37 AM
Try using:

document.test.blah.value = 2;

vs.

document.all.test.blah.value = 2;

roo141
02-13-2004, 11:57 AM
Thanks that worked

BUt the actual problem was that I had
type=Javascript instead of type = JavaScript

How stupid!

Any way now I have a new set of problems. I want to pass the name of the element as a parameter of the function like this.

<html>

<head>
<script type=text/JavaScript>
function updateValue(name)
{ document.test.name.value = 2;
}

</script>
</head>

<body>
<form name=test method=get>

<INPUT name=blah type=text value=0>

</form>

<img src=em.gif onClick=updateValue(blah)>

</body>

</html>

Howver this does not work.
Do I have to change the variable name in some way before I can use it?

Or maybe I have to pass the parameter differently?

jaegernaut
02-13-2004, 12:06 PM
You can use this instead:

document.getElementById(name).value = 2;

vs.

document.test.name.value = 2;

Just make sure to put quotes around blah in the call, i.e.:

<img src=em.gif onClick=updateValue('blah')>

roo141
02-13-2004, 12:10 PM
Yes,

that works perfectly!

It's actually part of a much bigger project, so i hope it works just as well there as in my little test.

thanks again!

jaegernaut
02-13-2004, 12:13 PM
You're welcome.

Glad I could help.
:D