Can't get jQuery-UI Modal Dialog to set value on submit
I've got a jQuery Modal dialog that prompts a user for their OpenID username. The problem is that I can't get the "Submit" function to set the username properly
<script>
var OpenIDAddress;
$('.openid_btn').click(function () {
switch ($(this).text()) {
case "Google":
$("#openid_identifier").val("https://www.google.com/accounts/o8/id");
break;
case "Yahoo!":
$("#openid_identifier").val("http://yahoo.com/");
break;
case "myOpenID":
OpenIDAddress = 'http://{username}.myopenid.com/';
openOpenIDDialog();
break;
}
});
// Manages the username window
$("#openid-username-dialog").dialog({
autoOpen: false,
resizable: false,
height: 140,
modal: true,
buttons: {
'Submit': function () {
开发者_StackOverflow社区 OpenIDAddress = OpenIDAddress.replace(/{username}/, $("openid-username").val());
$("#openid_identifier").val(OpenIDAddress);
$(this).dialog('close');
},
Cancel: function () {
$(this).dialog('close');
}
}
});
// Opens the Username Input Window
function openOpenIDDialog() {
$('#openid-username-dialog').css('display', 'inherit');
$('#openid-username-dialog').dialog('open');
return false;
}
</script>
Basically what I'm doing is using a case statement to decide which openID the user clicked.
If the openID Provider requires a username, then I open a modal dialog requesting the username.
Then, when the user presses submit, I want to run a regex to replace {username}
with the users entry.
The problem I'm having is that the when you click submit, I get the following in my input
http://undefined.myopenid.com/
FRIGGING SON OF A @#$%^
I forgot to add the hash mark
OpenIDAddress = OpenIDAddress.replace(/{username}/, $("openid-username").val());
should be
OpenIDAddress = OpenIDAddress.replace(/{username}/, $("#openid-username").val());
精彩评论