Javascript jQuery strip leading and trailing spaces -


i want trim value (strip leading , trailing spaces) , make first letter in every word capital. when user leave element (blur event)

html input follows

<input id="iptfirstname" name="iptfirstname" type="text"/>  

js piece of code

$(document).ready(function(){       var iptfirstname = $("#iptfirstname");      iptfirstname.blur(validateforename); });   function validateforename(){     var firstname= $("#iptfirstname").val;     //strip leading , trailing spaces     firstname= $.trim(firstname)     //change first letter in every word uppercase     firstname= capital(firstname);     //update input field whit new value     $("#iptfirstname").val(firstname); }  function capital(elevalue) {     var elevalue;      if (elevalue != "") {         var firstletter = elevalue.substring(0, 1).touppercase();         var restofword = elevalue.substring(1, elevalue.length).tolowercase();         elevalue = firstletter + restofword;         return elevalue;     }  } 

please understand why isn't working or maybe have better approach solve problem.

$(document).ready(function(){       var iptfirstname = $("#iptfirstname");      iptfirstname.blur(validateforename); });   function validateforename(){     var firstname= $("#iptfirstname").val();     //strip leading , trailing spaces     firstname= $.trim(firstname)     //change first letter in every word uppercase     firstname= capital(firstname);     //update input field whit new value     $("#iptfirstname").val(firstname); }  function capital(elevalue) {     var elevalue;      if (elevalue != "") {         var firstletter = elevalue.substring(0, 1).touppercase();         var restofword = elevalue.substring(1, elevalue.length).tolowercase();         elevalue = firstletter + restofword;         return elevalue;     }  } 

try must work, few changes done,

var firstname= $("#iptfirstname").val; 

to

var firstname= $("#iptfirstname").val();  touppercase 

to

touppercase  tolowercase 

yo

tolowercase 

Comments

Popular posts from this blog

objective c - Change font of selected text in UITextView -

php - Accessing POST data in Facebook cavas app -

c# - Getting control value when switching a view as part of a multiview -