LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 09-22-2003, 11:51 AM   #1
Linh
Member
 
Registered: Apr 2003
Posts: 178

Rep: Reputation: 30
Cannot activate Javascript within Python script


Cannot activate Javascript within the HTML page. This HTML page contains both Python and Javascript script. This HTML page is generated by a Python script.

When a user enter a non-numeric value in the text box, an alert message will prompt the user, and the non-numeric value is automatically deleted from the text box. This Javascript code does work if it contains only Javascript, but when it is within the code that Python generated, and I put in a non-numeric value, it said
"error on page" at the bottom left hand corner.

The code, below do not have a <form> <body> and <html> when View --> Source is done on Internet Explorer because the <form> <body> and <html> header are generated from another code.

===============================
Code:
#!/usr/bin/python

import os
import sys  

print """

<SCRIPT LANGUAGE="Javascript">
<!--

function only_numbers(txt)
 {
   var temp=new String();
   var temp2=""
   var count=0;

   if (!(event.keyCode == 48 || event.keyCode == 49 ||
         event.keyCode == 50 || event.keyCode == 51 ||
         event.keyCode == 52 || event.keyCode == 53 ||
         event.keyCode == 54 || event.keyCode == 55 ||
         event.keyCode == 56 || event.keyCode == 57 ||
         event.keyCode == 8))
     {
        temp = ip1.value;       //preserve the current contents of text field
        alert("Only numeric is allowed")
        ip1.value=""
          while(count<temp.length)
           {
              if(temp.charAt(count) >= '0' && temp.charAt(count) <= '9')
              ip1.value = ip1.value + temp.charAt(count);
              count++;
           }
     }
 }

//-->
</SCRIPT>

<input type=text size=3 maxlength=3 name=ip1 onkeyup='only_numbers(ip1.value)'><b>.</b> 

</form>
</body>
</html>

""" % (homeiserver,displayresult(res))
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
python cgi script and premature end of script headers Neruocomp Programming 1 07-28-2005 11:43 AM
I need a python code that activate a button Linh Programming 0 08-20-2004 10:47 AM
Question python javascript. moby Programming 2 07-16-2004 10:55 AM
javascript like shell script? jpbarto Programming 5 07-31-2003 05:30 PM
Javascript: New Window Script trickykid Programming 1 03-22-2001 01:58 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 09:27 PM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration