1

I am running the following Jquery:

<input type="text" value="hello" name="multy['helloworld']" />
<script type="text/javascript">
  $(document).ready(function(){
    var hello = 'helloworld';
    alert($('input[name="multy['+hello+']"]').val());
  })
</script>

As you'll see it can't select the element by a named Array key. Is there a work around for this?

Ta.

Antony

2 Answers 2

1

Yes, remove the single quotes from the name of the element:

<input type="text" value="hello" name="multy[helloworld]" />

They are absolutely not required.

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

2 Comments

Super thanks. I don't have reputation but will mark it as the answer.
Although in my other code I just cannot get this to work: select[name="timeSlots['+name+']"]
0

You have to do double escapes on the brackets when you send it to jquery so jquery will know to escape them, too. Plus, please notice that I removed the single quote from the input in your example.

<input type="text" value="hello" name="multy[helloworld]" />
<script type="text/javascript">
    alert($('input[name=multy\\[helloworld\\]]').val());
</script>

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.