kstolee
03-12-2007, 03:28 AM
I'm not letting my users choose a username, instead I'm using their email address to create it for them.
I have a simple jscript function that pulls their username from their email address. In that same function, I'm setting the value of the username element in the form. I'm pretty sure the function is running prior to the form being submitted, but upon testing, it tells me I haven't entered a username. I've included my code below:
function createUserName(email)
{
var emailIndex = email.indexOf("@") - 1;
document.forms.register.username.value = email.substr(1, emailIndex);
}
and then in the submit button, I've got this:
<input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" onClick=createUserName(email.value) />
Where have I gone wrong?
Seems I didn't do anything wrong, but when I pulled the username out of the form, I forgot to readd a hidden element, so although my code was working, it couldn't actually set the value of an element that didn't exist. I added the following:
<input type=hidden name="username" />
and it worked just beautifully. For anybody that might want to do something similar
I have a simple jscript function that pulls their username from their email address. In that same function, I'm setting the value of the username element in the form. I'm pretty sure the function is running prior to the form being submitted, but upon testing, it tells me I haven't entered a username. I've included my code below:
function createUserName(email)
{
var emailIndex = email.indexOf("@") - 1;
document.forms.register.username.value = email.substr(1, emailIndex);
}
and then in the submit button, I've got this:
<input type="submit" class="button" value="$vbphrase[complete_registration]" accesskey="s" onClick=createUserName(email.value) />
Where have I gone wrong?
Seems I didn't do anything wrong, but when I pulled the username out of the form, I forgot to readd a hidden element, so although my code was working, it couldn't actually set the value of an element that didn't exist. I added the following:
<input type=hidden name="username" />
and it worked just beautifully. For anybody that might want to do something similar