2

I have a form select element with name field_p_payment[value] and i need to catch this element and reset the select box , i used the following code ,

document.getElementsByName("field_p_payment[value]").selectedIndex='0'

But it doesnt seem worked , i also tried the jquery version as

$('[name="field_p_payment[value]"]').attr("selectedIndex","0");

But $('[name="field_p_payment[value]"]').prop("selectedIndex","0"); works .

But i cant use prop because am using an oldest version of jquery .Any solution ?

1 Answer 1

3

Usually getElementsByName returns the results in a HTML collection. So try,

document.getElementsByName("field_p_payment[value]")[0].selectedIndex='0'

Also read here for more information.

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

2 Comments

@Icecreamsandwich Glad to help!
Removed my duplicate ,answer +1

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.