value of the deletion input on click

Asked

Viewed 114 times

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?

  • <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; ?>"

  • 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.

  • 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

  • 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.

  • 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>

  • 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

Show 2 more comments
No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.