My javascript functions do not work in Python?

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • omertasci
    New Member
    • May 2012
    • 3

    My javascript functions do not work in Python?

    Code:
    #!C:/Python27/python.exe
    
    import cgi
    form = cgi.FieldStorage()
    
    a=int(form.getvalue('a','0'),0)
    b=int(form.getvalue('b','0'),0)
    
    
    print """Content-type: text/html
    
    <html>
      <head>
        <title>Greeting Page</title>
      </head>
      <b><h1>Welcome!</h1></b>
      <body>
       
          <script type="text/javascript">
       x=%d
       y=%d
          function add(x,y){     
          document.write(eval)(x)+(eval)(y);  }
    
          function sub(x,y){
          var t=(eval)(x)-(eval)(y);
          document.write(t);  }
          function mult(x,y){
          var t=eval)(x)-(eval)(y);
          document.write(t);  }
          function div(x,y){
          var t=eval)(x)/(eval)(y);
            document.write(t);  
                document.write("<p>this is<br/>"+"<i>division.be careful!</i> ? </p>");}
          </script>
    
        <form action='project2.py'>    
             first number:<input type='text' name='a' />
            second number:<input type='text' name='b' />
             <br><input type="button" value="add them" onclick="add()" />
             <input type="button" value="sub them" onclick="sub()" />
             <input type="button" value="mult them" onclick="mult()" />
             <input type="button" value="div them" onclick="div()" /></br>
        </form>
     
    
      </body>
    </html>
    """ % (a,b)
  • omertasci
    New Member
    • May 2012
    • 3

    #2
    Why these functions do not work?please look the code.

    Comment

    • Dormilich
      Recognized Expert Expert
      • Aug 2008
      • 8694

      #3
      it’s the usual. document.write( ) kills your whole page.

      Comment

      • omertasci
        New Member
        • May 2012
        • 3

        #4
        how is it?could you tell me the correct solution?

        Comment

        • Dormilich
          Recognized Expert Expert
          • Aug 2008
          • 8694

          #5
          could you tell me the correct solution?
          simply do not use document.write( ). there is a range of methods starting from .innerHTML up to the DOM methods.

          Comment

          Working...