Forum Moderators: open

Message Too Old, No Replies

Simple automated form value

array named

         

scriptmasterdel

9:23 pm on Aug 1, 2006 (gmt 0)

10+ Year Member



Hello World!

Here is my problem.

A simple js to set a value of a form field you would use something like this.

document.formname.inputname.value = 'whatever i choose';

My problem is ... My form input name is called:

"details[Price]"

So when i try and set the value it fails to do so, e.g.

document.formname.details[Price].value = 'whatever i choose';

Is there a simple solution?

Del

Code is below for you guys to copy and paste if need be.


<script>
function changePrice(finalValue)
{
document.formName.details[Price].value = finalValue;
}
</script>

<form name="formName">

<input name="details[Price]">

</form>

<a href="#" onClick="changePrice('22.99')">change</a>

garann

10:02 pm on Aug 1, 2006 (gmt 0)

10+ Year Member



Is there a simple solution?

...Other than changing the name of the element? :)

You could give it an ID, in addition to its name - something without confusing characters - and use

document.getElementById('yourSimplerID').value = finalValue;
to change it.

scriptmasterdel

10:14 pm on Aug 1, 2006 (gmt 0)

10+ Year Member



That's what i though, was looking for a way to use it with the element name.

Thank you.