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))