Click here to Skip to main content
15,890,438 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
In my project i'am passing text box value through json. When i put" <script> " as input value it now allows the value,but it will affect all my page design . i dont want to allow any tags. how can i do that.Will JSON.stringify works for this.if so how can i achieve.i also dont want to allow single quote,back slash.

JavaScript
function creList(){ 
 		var Name =$jq("#createew").val() ;
if(Name == "")
		{
  
	  $jq("#Err").dialog("option","modal",true).dialog("open");
		    $jq('#Err').css("min-height", '24px');
		    $jq('#Err').css("text-align", 'center');     
		    $jq('#Err').css("color", 'red');
		    $jq('#Err').text('Please  message');
		    $jq('#Err').css("font-size", '130%');
  
  
		}
		else
		{
			if( Name.indexOf('\'') > -1 || Name.indexOf('\\') > -1)
			{
			 Name=Name.replace(/'/g,'%27') ; 
		        Name=Name.replace(/\\/g,'%29');
		       }   
          $jq.ajax({ 
       	  type:"POST", 
	         url:"/pages.aspx/Create", 
	         data:"{liName:'" + Name + "' , pId: {PrId}}", 
	         contentType: "application/json; charset=utf-8", 
                dataType: "json", 
       	  success: onSuccess, 
	         error: onError 
	     }); 
		}
Posted
Updated 26-Dec-14 0:32am
v2
Comments
Prasad Khandekar 26-Dec-14 7:05am    
Hello,

You can use escapeHTML to properly escape the HTML content. However it will require more space while saving it in the persistent store. The better approach is to store the values as is and escape at the time of streaming from the server,
Regards,
MaddyHow 30-Dec-14 2:23am    
will json.stringify work...

1 solution

You can restrict user from entering special characters in TextBox. Refer - Restrict user from entering Special Characters in TextBox using JavaScript[^].
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900