i want to replace the “username” in the class of current selector with the username provided by the user in jquery dialog.problem is that i cant user $(this).attr() inside of jquery dialog button coz it will refer to the jquery dialog.Please suggest how to replace word username with user input in jquery dialog.Thanks in advance
<form action="#" method="post" >
</form>
<p id="text" class="www.username.google.com"> click me </p>
<div id="test" class="sandy" >
<input id="username" class="sandy1" />
</div>
==============================================================================
$('#text').click(function(){
var provider_url= $(this).attr('class');
$('.sandy').dialog({
buttons: {
"OK": function() {
if($('#username').val() == '') {
$('#username').focus();
} else {
var myvalue= $("#username").val();
var nextval= replace(provider_url, username,myvalue);
$(this).dialog('close');
alert(nextval);
$('form').append(nextval);
$('form').submit();
}
}
}
});
});
the jsfiddle code demo is at here http://jsfiddle.net/zCFD5/127/.Please help me out
Try this:
Example fiddle
It’s worth noting though that you should really use
dataattributes for this, rather than storing it in theclass. You’ll need to upgrade your version of jQuery to do this though.Also, I included the leading and trailing
.in the regex so that you’re definitely replacing the right part of the url in cases like this:http://www.username.superusername.com