Hey.
I was trying to write a page yesterday where an admin can register a user. I wrote some javascript so that when the forename or surnames are off focus, a script is run to take the forename and surname, concatenate them and put them in the username box as a suggestion. The code worked fine until later when I added the form tags around the inputs (forgot to do it earlier). Code below:
I can't see anything wrong with it but it only doesn't work when the form tags are there, I took them away and it worked again...but naturally I need them to send the form!
I was trying to write a page yesterday where an admin can register a user. I wrote some javascript so that when the forename or surnames are off focus, a script is run to take the forename and surname, concatenate them and put them in the username box as a suggestion. The code worked fine until later when I added the form tags around the inputs (forgot to do it earlier). Code below:
Code:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Admin ~ Users</title>
<link rel="stylesheet" href="../css/admin/users.css" />
<script type="text/javascript">
function username(){
if(document.getElementById('forename').value != ""){
if(document.getElementById('surname').value != ""){
name = document.getElementById('forename').value;
name = name + document.getElementById('surname').value;
name = name.toLowerCase();
document.getElementById('username').value = name;
}
}
}
</script>
</head>
<body>
<div class='error'><?PHP echo str_replace("\'", "'", $_GET['error']); ?></div>
<br />
<form id="adduser" action="users_new_app.php" method="post">
<table>
<tr>
<th>Field</th>
<th>Value</th>
</tr>
<tr>
<th>Forename</th>
<td><input type="text" name="forename" size="50" id="forename" /></td>
</tr>
<tr>
<th>Surname</th>
<td><input type="text" name="surname" size="50" id="surname" /></td>
</tr>
<tr>
<th>Username</th>
<td><input type="text" name="username" size="50" id="username" onfocus="javascript:username();" /></td>
</tr>
....
</table>
</form>
</body>
</html>
Comment