2

I'm trying to determine the selector for this form element:

   <form action="/php/edit_images_reorder.htm" method="post" name="draglist_form">
    <input type="hidden" name="new_order" value="abc" /> 
   ...

This is what I'm working with right now:

$("form > [name='new_order']").val(...)

I want to assign a value to this form element from a function. Anyone know what the correct selector is? Thanks!

6 Answers 6

10

I've just tested it and it works: http://jsfiddle.net/H2D8x/1/

$("form [name=new_order]").val("my value");

Regards.

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

Comments

0

That's the correct selector. Too short.

Comments

0

You were on the right track:

$('form input[name="new_order"]').val('This is the new value');

What wasn't working in your code?

Comments

0

try

$("form input[name='new_order']").val(...)

Or you could give it an id? easier and more performant.

HTH

Comments

0

I'd go with

$('input[name="new_order"]').val('newval');

But what you have should be fine.

Comments

0

What's your actual problem? The selector appears correct to me:

See http://jsfiddle.net/AP8VA/1/

I would note for consistency that you should have the quote marks the other way around - use double quotes to represent the attribute and single quotes to demarcate the Javascript string.

This is a better fit for HTML which strictly speaking should have double quotes around attributes.

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.