473,396 Members | 1,799 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

My javascript functions do not work in Python?

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
4 2065
Why these functions do not work?please look the code.
May 6 '12 #2
Dormilich
8,658 Expert Mod 8TB
it’s the usual. document.write() kills your whole page.
May 6 '12 #3
how is it?could you tell me the correct solution?
May 6 '12 #4
Dormilich
8,658 Expert Mod 8TB
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

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

Similar topics

76
by: Nick Coghlan | last post by:
GvR has commented that he want to get rid of the lambda keyword for Python 3.0. Getting rid of lambda seems like a worthy goal, but I'd prefer to see it dropped in favour of a different syntax,...
2
by: Dot net work | last post by:
Is toString() compatible with all browsers? I don't know where to look on the internet to find out what javascript functions are ok to use with what browsers. I tried www.quirksmode.org but as...
3
by: Nikki | last post by:
Hi, I would like to create a central storage place for javascript functions that I can then access from any of my asp.net projects. An example of what I need it for is as follows: I have a...
1
by: Gerald Klix | last post by:
I read the whol email thread carefully and could not find any sentence by Guido, which states that he does not accept ctypes for the standard library. He just declined to rewrite winreg. Did I miss...
12
by: Arash Partow | last post by:
Hi all, I've ported various hash functions to python if anyone is interested: def RSHash(key): a = 378551 b = 63689 hash = 0
2
by: Bruce One | last post by:
When I put an UpdatePanel (Atlas control) araound my ServerControls they all seem to vanish from the page (I cant find them in my source page...). So the browser fires an exception telling the...
5
by: Vyz | last post by:
Hi, I have a script with hundreds of lines of javascript spread accross 7 files. Is there any tool out there to automatically or semi-automatically translate the code into python. Thanks Vyz
3
by: Matthew Lock | last post by:
Hello, I am automating Internet Explorer in order to do some simple automated testing of a web application. How do I invoke Javascript functions in the web page I load? I can successfully start...
6
by: mcfly1204 | last post by:
I have a page that contain input form, a contact us page. I also have a few javascript functions, one in particular sends the visitor back to the home page. My javascript is not functioning...
6
by: Blackmore | last post by:
I'd like to screate a link to my javascript functions, such that they do not appear in the page source code and users cannot tamper with them. I've noticed that other websites appear to be able to...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.