Javascript creating a username using inputs

I have a form in which the user inputs various information. The input chosen name allows the user to enter a username of choice but a HIDDEN INPUT needs to be integrated so that a system username is created.

The system username is generated on page submit by a javascript function, and it consists of the first alphabetic characters found in the Family name, street address, Given name; the numerical day of the month; and the numerical seconds field of the time of submission. E.g.: A user registers with name Bernardo O’Higgins, address 213 Liberator St, at 12:31:16 on 25 April 2014. His system username is OLB2516. Just so i can see if it works, at the moment the ssytem username is not hidden but just a normal text box.

I am totally lost as i do not know how to go about this and hoping somebody can help me? Here is my php file with form integrated.

<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"

<html xmlns="" xml:lang="en" lang="en">

<link rel="stylesheet" type="text/css" href="stylesheet.css" />



$conn = mysql_connect("localhost", "....", ".....");
mysql_select_db("tipping291", $conn)
or die ('Database not found ' . mysql_error() );


<div id="container">
<div id="header">


<div id="menu">
<a href="home.php"><h2>Homepage</h2></a><br />
<a href="rego.php"><h2>Registration</h2></a><br />
<a href="userlogin.php"><h2>User Login</h2></a><br />
<a href="adminlogin.php"><h2>Administrator Login</h2></a><br />
<a href="tipping.php"><h2>Tipping</h2></a><br />
<a href="termsnconditions.php"><h2>Terms & Conditions</h2></a><br />

<form id="rego" action="<?php echo 
htmlspecialchars($_SERVER["PHP_SELF"]);?>" method="post" onSubmit="return       validateForm()">

<label>Given Name:</label> <input type="text" name="gname"><br />
<br />
<label>Middle Name: </label><input type="text" name="mname"><br />
<br />
<label>Family Name:</label> <input type="text" name="surname"><br />
<br />
<label>Chosen Username:</label> <input type="text" name="username"><br />
<br />
<label>Address:</label> <input type="text" name="address"><br />
<br />
<label>Postcode: </label><input type="text" name="postcode"><br />
<br />
<label>State:</label> <input type="text" name="state"><br />
<br />
<label>Tel number: </label><input type="text" name="tel"><br />
<br />
<label>Password:</label> <input type="password" name="password"><br />
<br />
<label>Password confirmation:</label> <input type="password" name="passconfirm"><br />
<br />
<label>System username</label> <input type="text" name="susername" >
<input type="submit" value="submit">





I think the code found here is more suitable to generate a random string (you can put 20 characters instead of 10)

You can also just use md5() in the time or user email...

And you don't need to worry to create it in javascript, if this is random generated you can do that in php.

If you really need to do in javascript... there's CaffGeek answer in this post.. who could help you


Add the below code before closing } of function validateForm() { and try

var username = '';
var date = new Date();
$.each(['surname', 'address', 'gname'], function() {
    username += $.trim($('input[name="' + this + '"]').val().replace(/\d+/g, '')).substring(0, 1);
username += date.getDate() + '' + date.getSeconds();



Recent Questions

Top Questions

Home Tags Terms of Service Privacy Policy DMCA Contact Us

©2020 All rights reserved.