By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
460,036 Members | 978 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 460,036 IT Pros & Developers. It's quick & easy.

My javascript functions do not work in Python?

P: 3
Expand|Select|Wrap|Line Numbers
  1. #!C:/Python27/python.exe
  2.  
  3. import cgi
  4. form = cgi.FieldStorage()
  5.  
  6. a=int(form.getvalue('a','0'),0)
  7. b=int(form.getvalue('b','0'),0)
  8.  
  9.  
  10. print """Content-type: text/html
  11.  
  12. <html>
  13.   <head>
  14.     <title>Greeting Page</title>
  15.   </head>
  16.   <b><h1>Welcome!</h1></b>
  17.   <body>
  18.  
  19.       <script type="text/javascript">
  20.    x=%d
  21.    y=%d
  22.       function add(x,y){     
  23.       document.write(eval)(x)+(eval)(y);  }
  24.  
  25.       function sub(x,y){
  26.       var t=(eval)(x)-(eval)(y);
  27.       document.write(t);  }
  28.       function mult(x,y){
  29.       var t=eval)(x)-(eval)(y);
  30.       document.write(t);  }
  31.       function div(x,y){
  32.       var t=eval)(x)/(eval)(y);
  33.         document.write(t);  
  34.             document.write("<p>this is<br/>"+"<i>division.be careful!</i> ? </p>");}
  35.       </script>
  36.  
  37.     <form action='project2.py'>    
  38.          first number:<input type='text' name='a' />
  39.         second number:<input type='text' name='b' />
  40.          <br><input type="button" value="add them" onclick="add()" />
  41.          <input type="button" value="sub them" onclick="sub()" />
  42.          <input type="button" value="mult them" onclick="mult()" />
  43.          <input type="button" value="div them" onclick="div()" /></br>
  44.     </form>
  45.  
  46.  
  47.   </body>
  48. </html>
  49. """ % (a,b)
  50.  
May 6 '12 #1
Share this Question
Share on Google+
4 Replies


P: 3
Why these functions do not work?please look the code.
May 6 '12 #2

Dormilich
Expert Mod 5K+
P: 8,639
itís the usual. document.write() kills your whole page.
May 6 '12 #3

P: 3
how is it?could you tell me the correct solution?
May 6 '12 #4

Dormilich
Expert Mod 5K+
P: 8,639
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.
May 7 '12 #5

Post your reply

Sign in to post your reply or Sign up for a free account.