Hi everyone.
I'm having a very seriouse problem where I have a textbox and I want a button and I want to take whatever a user type in this textbox/textarea and set it to the data-name
which is a button's parameter. Here is the codes.
Textarea: <input type="text" id="dCell" value="Cellphone Number" maxlength="10" onkeypress="checkmax(this)" name="CellphoneNumber2" id="cCell" onfocus="this.value = '';" onblur="if (this.value == '') {this.value = 'Cellphone Number';}" required>
Button:<button id="cCart" class="btn btn-danger my-cart-btn my-cart-b" data-id="16" data-name="testbutton" data-summary="summary 16" data-price="50" data-quantity="1" data-image="images/of15.png">Buy Airtime</button>
The code I tried:
function checkmax(element){
if(element.value.length == 9){
//var idNumber = $('#dCell').val();
$(function() {
$('dCell').change(function() {
$('#cCart').data('data-name', this.value);
});
});
}else{
}
}
I can't seem to make this work. I want to assign whatever the user typed to the button on the 'data-name' so it will change from testbutton to whatever the user typed. How can I get that working?