Click to See Complete Forum and Search --> : escape characters?


kinetek
08-11-2003, 10:35 PM
i was wondering if it was possible to set a form field value with javascript. the problem is the form name has square brackets in it and this causes an error.

here is the code that i'm using to set the value:
document.cart_quantity.id[1].value = 'value';

is there a way around this?

pyro
08-11-2003, 10:42 PM
Reference it through the forms elements array, like this:

document.cart_quantity.elements["id[1]"].value = "value";

Charles
08-12-2003, 05:30 AM
That might work on some browsers, but the problem is that your HTML is invalid. From the HTML 4.01 Specification:
ID and NAME tokens must begin with a letter ([A-Za-z]) and may be followed by any number of letters, digits ([0-9]), hyphens ("-"), underscores ("_"), colons (":"), and periods (".").
http://www.w3.org/TR/html4/types.html#type-idThe proper solution is to change your form filed names.