<head> <SCRIPT type=text/javascript> function html2entities(){ var re=/[(<>"'&]/g for (i=0; i<arguments.length; i++) [B]arguments[i].value=arguments[i].value.replace(re, function(b){return replacechar(b)})[/B] } function replacechar(match){ if (match=="<") return "<" else if (match==">") return ">" else if (match=="\"") return """ else if (match=="'") return "'" else if (match=="&") return "&" } </SCRIPT> </head> <body> <FORM> <TEXTAREA style="WIDTH: 400px; HEIGHT: 100px" name=data1></TEXTAREA><BR> <INPUT onclick=html2entities(this.form.data1) type=button value="Convert special chars to entities"> </FORM> </body> </html> Code (markup): This JavaScript converts special HTML characters to their entities version inside user entered data such as a TEXTAREA before the form is submitted. i have some questions. Please help me. I spend over 2 weeks to know it but i can't What this code use for???: arguments.value=arguments.value.replace(re, function(b){return replacechar(b)}) This function function(b){return replacechar(b) without name just include parameter. What they call??? Parameter b use for what?
the function can have multiple parameters "arguments" is a reserved variable in javascript that reads the passed parameters in a function.. it is an array, so you can loop it for you to be able to access all the parameters passed.. about function(b){return replacechar(b).. it will be the shorthand of.. var temp_func = function(b){ return replacechar(b) }; arguments[i].value=arguments[i].value.replace(re,temp_func); Code (markup): b is the string found in the arguments.value to be replaced..