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,655
  • 1
  • 29
  • 41

4 Answers4

2

yes you can do this by escape it.

$('#\\.Verify_Password');

OR

$("[id='.Verify_Password']")
Dipesh Parmar
  • 27,090
  • 8
  • 61
  • 90
1

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

Community
  • 1
  • 1
DGS
  • 6,015
  • 1
  • 21
  • 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
  • 732,580
  • 175
  • 1,330
  • 1,459
ssilas777
  • 9,672
  • 4
  • 45
  • 68
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());
});
GautamD31
  • 28,552
  • 10
  • 64
  • 85