Click here to Skip to main content
15,891,708 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi,

I have a input button ,one div tag and one textbox as follow

<input type="button" runat="server" onclick="add();" />

 <input type="text" runat="server"  />

<div id="hhh"></div>


  <script type="text/javascript">


       function add() {

           document.getElementById("hhh").innerHTML = document.getElementById("TextBox1").value;
       }

   </script>


What i want is when suppose user write inside the texbox some script like
XML
<div > hi <script type="text/javascript">

                       alert();

          </script> </div>
</pre>   
and press the button alert msg should be called.
Posted
Comments
Mohibur Rashid 23-Jul-14 6:05am    
so, what is stopping you?
Kornfeld Eliyahu Peter 23-Jul-14 6:05am    
Look for JavaScript eval function, and be prepared to evil!!!
aassaahh 23-Jul-14 6:22am    
eval function is written in server side,i want user should write javascript code inside the textbox ,when wen user press enter ,the javascript function should get executed,
aassaahh 23-Jul-14 6:28am    
user will be able to write any javascipt code in the texbox and will press the button,the code written inside the texbox should be get executed for eg ,if a user write a script as "<div> alert will be called without mouseover or without click <script>alert() </div>" and press the button ,alert should be called .

1 solution

Try this:
XML
<!DOCTYPE html>
<html>
<body>
    <input type="text" id="jssyntax" placeholder="type js here" value="">
    <button onclick="myFunction()">Run it</button>
<script>
function myFunction() {
    var syntax = document.getElementById("jssyntax").value;
    eval(syntax);
}
</script>
</body>
</html>
 
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