简体   繁体   中英

JQuery grab value of hidden field

I am trying to get the value of a hidden field using a selector on the input file field, as shown in my code below, but I am always getting undefined as the returned value, can someone please tell me what I am missing / doing wrong here? Thanks.

                    <form id="form1" method="POST">                            
                        <input type="hidden" id="docID1" name="docID1" value="1234">
                        <div class="fileUpload">
                            <button id="uButton" onclick="return false;">Browse</button>                                
                            <input id="uplA" name="uplA" type="file" class="upload" multiple />
                        </div>
                    </form>

Query:

var docIDInHiddenField = $('#uplA').parent('[name=docID1]').val();
console.log(docIDInHiddenField); //return undefined

You have incorrect selector. hidden input is immediate previous sibling of #uplA s parent. you need to use:

 $('#uplA').parent().prev().val();

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM