mari
July 16, 2012, 1:09pm
1
Hi Guys,
I have a php form with a field called Email address, i also have another field called username
I would like to auto populate the username field with what has been entered into the email address field
i know how to pull the variable form the database…however in this case the field needs to auto populate before it is submitted to the database
is this possible? if not with php then is it possible with javascript
thanks
You’re wanting it to populate without submission, it’ll have to be javascript.
Something along the lines of (and i’m probably partly pseudocoding)
<input type='text' id='email'..... onBlur='quack()'>
<script type='text\\javascript'>
function quack() {
if(document.getElementById('username').value == '') {
document.getElementById('username').value = document.getElementById('email').value;
}
}
</script>
ralphm
July 16, 2012, 1:26pm
3
Sounds more like a job for JavaScript. But it sounds like you want the email address that is typed in to appear straight away in the username field. Why would you want that? It sounds like an annoyance to me.
mari
July 16, 2012, 2:43pm
4
StarLion:
You’re wanting it to populate without submission, it’ll have to be javascript.
Something along the lines of (and i’m probably partly pseudocoding)
<input type='text' id='email'..... onBlur='quack()'>
<script type='text\\javascript'>
function quack() {
if(document.getElementById('username').value == '') {
document.getElementById('username').value = document.getElementById('email').value;
}
}
</script>
Hi, i tried that, it doesnt seem to work
here is my current form code
<TR><TD CLASS="mainlightest" >Email Address *</TD><TD CLASS="mainlightest" ><INPUT TYPE="TEXT" NAME="email_address" value="EMAIL_ADDRESS" /></TD></TR>
<TR>
<TD CLASS="mainlightest" >Username *</TD><TD CLASS="mainlightest" ><INPUT TYPE="TEXT" NAME="username" value="USERNAME" /></TD></TR>
<script type="text/javascript">
function quack() {
if(document.getElementById('username').value == '') {
document.getElementById('username').value = document.getElementById('email_address').value;
}
}
</script>
Gman
July 16, 2012, 3:25pm
5
mari:
Hi, i tried that, it doesnt seem to work
here is my current form code
<TR><TD CLASS="mainlightest" >Email Address *</TD><TD CLASS="mainlightest" ><INPUT TYPE="TEXT" NAME="email_address" value="EMAIL_ADDRESS" /></TD></TR>
<TR>
<TD CLASS="mainlightest" >Username *</TD><TD CLASS="mainlightest" ><INPUT TYPE="TEXT" NAME="username" value="USERNAME" /></TD></TR>
<script type="text/javascript">
function quack() {
if(document.getElementById('username').value == '') {
document.getElementById('username').value = document.getElementById('email_address').value;
}
}
</script>
You need to add id=“username” for you input field as well as email
As Gman said. If you look at my input field in the code, i specify an id attribute.
GetElementById works on… ID. not name.