JavaScript/Jquery Auto Generate Employee Id based on user input -
i'm generating empid using servlet boss wants when user typing, see empid instantly based on inputs. , i'm not familiar javascript or jquery, think it's right tool this. please help?
empid contains first character in first name, middle name, , surname plus dash , date of birth. sample jhd-01011990.
here's simplified version of html form:
<form method="post" action="../profile/saveprofile"> <label for="empid">employee id</label> <input id="empid" name="empid" type="text" placeholder="fml-mmddyyyy" required readonly> <label for="title">title</label> <select id="title" name="title"> <option value="0"></option> <option value="1">attorney</option> <option value="2">doctor</option> <option value="3">professor</option> <option value="4">engineer</option> </select> <label for="fname">name</label> <input id="fname" name="fname" type="text" placeholder="* first name" required> <input id="mname" name="mname" type="text" placeholder="* middle name" required> <input id="lname" name="lname" type="text" placeholder="* surname" required> <input id="ename" name="ename" type="text" placeholder="ext"> <label for="dob">* date of birth</label> <input id="dob" name="dob" type="text" required> <label for="doa">date of original appointment</label> <input id="doa" name="doa" type="text"> <button type="button">close</button> <button type="submit">save</button> </form> and if needed, here's java code generating empid
public string generateemployeeid(string dateofbirth, string firstname, string middlename, string surname) { string[] birthdate = dateofbirth.split("-"); string empid = firstname.charat(0) + middlename.charat(0) + surname.charat(0); empid += "-" + birthdate[1] + birthdate[2] + birthdate[0]; return empid; } i'd post sample screen shot of form can't. please tell me if need it.
thank you!
here's jquery code:
$(function() { $("#fname,#mname,#lname,#dob").keyup(function() { var birthdate = $("#dob").val().split('-'); var fname = $("#fname").val(); var lname = $("#lname").val(); var mname = $("#mname").val(); var empid = fname.charat(0) + mname.charat(0) + lname.charat(0) + '-' + birthdate.join(''); $("#empid").val(empid); }); }); it's straightforward translation of java code, wrapped in jquery event handler, , using .val() values input fields.
Comments
Post a Comment