javascript - How do I get the value from a data-selected input option? -
how can data-selected's value input? let's want "title" value that?
$( document ).ready(function() { //console.log("prdcl ready"); $("#digital_object_prdcls__0__prdcl_links__0__ref_").on('keyup change', prdcl_link); $("#digital_object_prdcls__0__volume_num_").on('keyup change', prdcl_link); $("#digital_object_prdcls__0__issue_num_").on('keyup change', prdcl_link); function prdcl_link(){ //console.log("entered function"); var valp = {}; valp = $("#digital_object_prdcls__0__prdcl_links__0__ref_").data('data-selected'); console.log(valp); var valv = $("#digital_object_prdcls__0__volume_num_").val(); //console.log(valv); var vali = $("#digital_object_prdcls__0__issue_num_").val(); //console.log(vali); }; });
<input type="text" class="linker initialised" id="digital_object_prdcls__0__prdcl_links__0__ref_" data-label="publication" data-label_plural="publications" data-name="ref" data-path="digital_object[prdcls][0][prdcl_links][0]" data-url="/search.json" data-browse-url="/search.js?" data-selected="{"lock_version":0,"publication":"1111","publisher":"1111","title":"1111 (1111)","created_by":"admin","last_modified_by":"admin","create_time":"2016-06-01t14:46:46z","system_mtime":"2016-06-01t14:46:46z","user_mtime":"2016-06-01t14:46:46z","jsonmodel_type":"prdcl_title","uri":"/prdcl_titles/9"}" data-multiplicity="one" data-format_template="title" data-types="["prdcl_title"]" style="display: none;">
don't use first data-
chunk of attribute in code:
valp = $("#digital_object_prdcls__0__prdcl_links__0__ref_").data('selected');