0

Here is my current code:

jQuery(document).ready(function($) {
  $("#edit-name").change(function() {
    $("#Membership_UserName").val($(this).val());
  });
  $("#edit-pass-pass1").change(function() {
    $("#Membership_PassWord").val($(this).val());
  });
  $("#edit-pass-pass2").change(function() {
    $("#.Verify_Password").val($(this).val());
  });
});

Everything works fine, except for updating the value of the element whose ID is .Verify_Password. The reason seems pretty apparent to me (that jQuery is getting confused after seeing # and . right next to each other) but maybe that's wrong...

Regardless, the ID can't be changed because it's being sent to a remote endpoint and it needs to match on that end.

So my question is: is there a way to tell jQuery that .Verify_Password is an ID (and not a class)?

jerdiggity
  • 3,595
  • 1
  • 24
  • 40

4 Answers4

2

yes you can do this by escape it.

$('#\\.Verify_Password');

OR

$("[id='.Verify_Password']")
Dipesh Parmar
  • 26,601
  • 7
  • 57
  • 86
1

Try $("#\\.Verify_Password").val($(this).val()); or read up on jQuery selector value escaping

Community
  • 1
  • 1
DGS
  • 6,027
  • 1
  • 19
  • 37
1

You should double escape it

 $("#\\.Verify_Password").val($(this).val());

Check this jQuery doc for more info, Few examples -

// Does not work
$("#some:id")

// Works!
$("#some\\:id")

// Does not work
$("#some.id")

// Works!
$("#some\\.id")
marc_s
  • 704,970
  • 168
  • 1,303
  • 1,425
ssilas777
  • 9,476
  • 4
  • 43
  • 66
1

If you indicate a selector with # then it will be an ID or if you indicate a selector witn . then it will be an CLASS.

If you didnt know whether it is an id or class then try like

$("#edit-pass-pass2").change(function() {
    $("#\\.Verify_Password").val($(this).val());
});
Gautam3164
  • 28,027
  • 10
  • 58
  • 83