1

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.

1 Answer 1

1

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?

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.