0

I want add the return value from var Selectedvalue to hidden field id="Branchidhidden" in its value.

jQuery:

function Branch() {
    var Selectedvalue =  $( "#Branchitemtypeid option:selected" ).val(); //The return value is correct 
    $('#Branchidhidden').attr('value', Selectedvalue)
}

HTML:

<input type="hidden" id="Branchidhidden" name="Branchidhidden"  value=""/>

When I see the view-source value in hidden field is empty.

5
  • can you please post your full code ? I mean the select and options part too Commented Nov 3, 2017 at 14:14
  • 1
    Possible duplicate of jquery setting hidden input value not working as expected in IE7 and IE8 Commented Nov 3, 2017 at 14:15
  • You need to set the value attribute: .attr('value', Selectedvalue) This is a duplicate question. Commented Nov 3, 2017 at 14:16
  • use .val(yourValue) on that input, but remove the value="" attribute from hidden input tag Commented Nov 3, 2017 at 14:34
  • use PROP instead of ATTR Commented Nov 3, 2017 at 14:35

1 Answer 1

1

use PROP/VAL instead of ATTR

function Branch() {
    var Selectedvalue =  $( "#Branchitemtypeid option:selected" ).val(); //The return value is correct 
    $('#Branchidhidden').prop('value', Selectedvalue);

    // or val
    $('#Branchidhidden').val(Selectedvalue);
}
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.