I would like to perform a whois-query if a user enters a valid domain. This query should be done using AJAX.
This script calls function checkDomain()
always if the user types something into the form field:
js = jQuery.noConflict();
js(document).ready(function() {
jQuery('#jform_domain').keyup(function() {
checkDomain();
});
});
function checkDomain() {
var $this = jQuery(this);
jQuery.ajax({
url: '<?php echo JUri::root(); ?>/index.php',
dataType: 'json',
type: 'POST',
data: {
option: 'com_domaincheck',
format: 'json',
task: 'domain.checkDomain',
domain: jQuery("#jform_domain").val(),
'<?php echo JSession::getFormToken(); ?>': 1
},
success: function(response) {
if (response.success) {
console.log(response);
jQuery("#test").html(response.message);
// if (response.message == true) {} else {}
} else {
alert(response.message);
}
},
error: function(data) {
//console.log(data);
}
});
};
Now I would like to reduce unnecessary operations and start the script only, if the user entered a domain like:
example.com
It would be really, really, really cool, if the script would change inputs like www.example.com
or http(s)://www.example.com
to example.com
aswell.
I'm a beginner in JS and jQuery, so please do not blame me for my bad knowledge - I try to learn ;-)