I am trying to add a domain after a name field and not having success. name field @domain.com
$doc = JFactory::getDocument();
$js = "
jQuery(document).ready(function($){
// Define the variables
var regForm = $('#member-registration');
var name = regForm.find('#jform_name'); @domain.com<<<
var password = regForm.find('#jform_password1');
var password2 = regForm.find('#jform_password2');
var email = regForm.find('#jform_email1');
var email2 = regForm.find('#jform_email2');
regForm.find('.spacer').parents('.control-group').hide();
regForm.find('.star').hide();
email.parents('.control-group').hide();
password2.parents('.control-group').hide();
email2.parents('.control-group').hide();
password.on('keyup', function() {
password2.val( this.value );
});
name.on('keyup', function() {
email.val( this.value );
});
email.on('keyup', function() {
email2.val( this.value );
});
});
";
$doc->addScriptDeclaration($js);
Adding the domain would then allow the registration to pass the email stage and generate a email. I don't want to require a user to register with a email since I myself am a email provider.
name.on('keyup', function() {
email.val( this.value );
});
thanks for any advice.. been at it for a couple days now.
Hello thank you for your question
Try below code to get exact domain
$(document).ready(function(){
var domain = window.location.hostname;
if(domain.indexOf('www.') >= 0)
{
domain = domain.replace('www.', '');
}
domain = "@"+domain;
$("#name").on('keyup', function() {
var inputVal = $(this).val();
if($(this).val().indexOf(domain) >= 0)
{
inputVal = inputVal.split(domain);
inputVal = inputVal[0];
}
$(this).val(inputVal+domain)
setCaretToPos(document.getElementById("name"), inputVal.length);
});
$( "#name" ).keypress(function(e) {
var key = e.keyCode;
if (key >= 48 && key <= 57 || key == 32) {
e.preventDefault();
}
});
function setSelectionRange(input, selectionStart, selectionEnd) {
if (input.setSelectionRange) {
input.focus();
input.setSelectionRange(selectionStart, selectionEnd);
}
else if (input.createTextRange) {
var range = input.createTextRange();
range.collapse(true);
range.moveEnd('character', selectionEnd);
range.moveStart('character', selectionStart);
range.select();
}
}
function setCaretToPos (input, pos) {
setSelectionRange(input, pos, pos);
}
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<p>Name -</p>
<input type="text" placeholder="Enter name" id="name" />