-----------SOLVED-----------
thanks for taking the time to help me. i managed to make it work now. i think the problem was my negligence. i have to add the getVal
on my modal like so id="modal_"getVal
. it was calling the wrong modal, thats why the input box returns empty. Im very sorry for this and I appreciate the help people do. thank you
i have a simple modal which contains a textbox and button.
<input type="text" class="form-control" id="textb" val_A="1">
<button type="button" id="but"> submit </button>
i want to get the textbox .val()
and the attributes val_A
upon button click
$(document).on('click','#but', function() {
name = $('#textb').attr('value');
val_A = $('#textb').attr('val_A');
alert(name + "-" + val_A);
});
but Im getting undefined result for the name
.
ive also tried $('#textb').val();
and it didn't worked.
please note that i want the values from a textbox inside a modal, and not sure if theres a different approach of getting values considering modal behaviour.
----------[update]-----------
When this button is clicked, modal will appear
<button type="button" class="btn" val="1"> show modal </button>
The button has a specific value with it, val=1
which then activates a specific modal. thus, $(#modal_+getVal)
.
$(document).on('click','.btn', function () {
getVal = $(this).attr('val');
$('#modal_+getVal').modal({show:true})
});
Which then brings me to my question above. after the modal appears, i want to get the value of the textbox upon clicking yet, another button inside the modal.
but all it shows is undefined