asp.net - How to capitalise first letter of string in javascript? -
i have created 1 form. in form there 10 textbox , 1 button. when user enters text textbox , loses focus, first letter of string should capitalised. think javascript best option this. onblur event of 10 textbox have call it. don't want call onbuttonclick event.
// javascript function
function capitalisefirstletter(string) { return string.charat(0).touppercase() + string.slice(1); }
// cs file
page_load() { string s1 = textbox1.text.trim(); textbox1.attributes.add("onblur",capitalisefirstletter('"+s1+"')) }
but s1 empty because i've called function in pageload(). how can handle it?
do this...
page_load() { textbox1.attributes.add("onblur", "capitalisefirstletter('" + textbox1.clientid + "')"); }
modify javascript function below...
function capitalisefirstletter(txtid) { var txtstring = document.getelementbyid(txtid).value; document.getelementbyid(txtid).value = txtstring.charat(0).touppercase() + txtstring.slice(1); }
Comments
Post a Comment