Reputation: 227
I have a form with multiple inputs. One of the inputs is a text area. Here is the beginning of its opening tag:
<textarea id="edit-about-me-input" class="edit-website-input" type="text" name="edit-profile[byc_about_me]"...
As you can see, I have chosen to name it as an array, so that, when I post the form, I only have one array of values to deal with.
However I am running into a problem when trying to run a javascript function on that name.
Here is the rest of the text area's declaration:
onKeyDown="limitText(this.form.edit-profile[byc_about_me],this.form.countdown,1000);"
onKeyUp="limitText(this.form.edit-profile[byc_about_me],this.form.countdown,1000);"><?php echo $byc_about_me; ?></textarea>
Obviously, javascript does not like the dashes and brackets. Does anyone have a solution for me? Can I give it two names or something or do I need to rewrite the php that processes this form?
Thanks in advance.
Upvotes: 1
Views: 29
Reputation: 6179
Simply use square bracket notation instead of dot notation to access the edit-profile[byc_about_me]
property of the form
object, like so:
this.form['edit-profile[byc_about_me]']
It's not pretty, but it works!
Related: How do I reference a javascript object property with a hyphen in it?
Upvotes: 1