0
I have this code in javascript
which I pass values to inputs
. When I use this code it inserts the data into input
usually but when I do one click
after passing the values the input
automatically delete the entered value. If I replace this.getAttribute('data-email')
by a string
for example: user_email = "abc"
the value is passed to mine input
but it’s not erased when I do click
. how do I pass the value so that it is not deleted?
$('.userEdit').click(function() {
var user_email = this.getAttribute('data-email');
var user_type = this.getAttribute('data-type');
var user_function = this.getAttribute('data-function');
function myFunc(elem, val) {
return document.getElementById(elem).value = val;
}
myFunc("edit_form_user_email", user_email);
});
Like the button (or element) that has the class
userEdit
is defined?– carlosfigueira
<a class="btn btn-Warning btn-Xs userEdit" data-toggle="modal" href="#" data-target="#userEdit" data-email="<? php echo $user_f->users_email;? >" data-type="<? php echo $user_f->fk_user_type; ? >" data-Function="<? php echo $user_f->fk_user_function; ?>"
– Aron Brivio
You have a problem with the PHP code that is generating this page, not Javascript. Take a look at the source code of the page on browser to see the value being filled in the field
data-email
. You can also compare with http://jsfiddle.net/orfge35a/, which shows that your code works well, as long as the . userEdit HTML is correct.– carlosfigueira
It’s all right with PHP- If I give an Alert(user_email) it returns me the email perfectly that I took the data-email with php
– Aron Brivio
Try debugging the code in Javascript, and compare it to the jsfiddle I sent, to see what the difference is. Or add more details to your question so we can better understand what’s going on.
– carlosfigueira
I replaced in the <a> tag the " data-email="<? php echo $user_f->users_email;?>" for data-email="abc" and it returned me in the input this value "abc", but when I click in or out of the input this value automatically disappears. If I don’t use the javascript code getattribute() the error no longer occurs and the values are no longer deleted, but I need getattribute() to be able to recover the values I want inside my <a element>
– Aron Brivio
Post your html so we can help you better, I see, if you have the userEdit class in all your inputs, clicking one of them will erase the value of the email
– Gabriel Rodrigues