Accessing form element with non-conventional naming

W

William Holroyd

I haven't been able to find any resources on the internet about this and my
javascript books don't mention how to do this. So hopefully one of you guys
might be able to help me with this.

I'm building a website that needs to be able to check the value of an
element and give it a new value based on what it's current value is.

So for example, if I had a product and my code read like this...

<input type="text" name="name" size="20"><br>
<input type="text" name="description" size="20"><br>
<select size="1" name="public">
<option value="1">on</option>
<option value="0">off</option>
</select>

Assuming the name of my form was "form", I could access the value of the
text fields by "window.document.form.FIELDNAME.value" and the select by
"window.document.form.public.selectedIndex". But the page i'm working with
has multiple products listed and so I've addopted a nming convention for the
elements name's so that I could access it more efficiently in PHP. So for
example, I'd have multiple products as such...

<input type="text" name="product[1][name]" size="20"><br>
<input type="text" name="product[1][description]" size="20"><br>
<select size="1" name="product[1][public]">
<option value="1">on</option>
<option value="0">off</option>
</select>

<input type="text" name="product[2][name]" size="20"><br>
<input type="text" name="product[2][description]" size="20"><br>
<select size="1" name="product[2][public]">
<option value="1">on</option>
<option value="0">off</option>
</select>

<input type="text" name="product[3][name]" size="20"><br>
<input type="text" name="product[3][description]" size="20"><br>
<select size="1" name="product[3][public]">
<option value="1">on</option>
<option value="0">off</option>
</select>

But the problem is trying to interface these elements. How would I be able
to read the value of one of these elements?

Any help would be much appreciated.

-William
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top