I have tried googling this info for hours and am not sure if I am just not searching correctly. Everything I have seen says their textarea has information separated by commas and they want to do something else. I am trying to figure out how to actually make sure users enter string values separated by commas (so either while entering a message occurs if they enter a ; etc or upon submit a validation occurs). I am wanting the values separated by commas because upon submit, I have the strings entered into an array using split with commas as the deliminator. I am using html, javascript, and python. Please don't ask me to use other languages or to not use cgi as I don't have the capability of adding anything to my class computer. Thank you for any help!
HTML code:
<html>
<head>
<script type='text/javascript'>
function track()
{
var xhttp = new XMLHttpRequest();
var tnum=document.getElementById('tnum').value; //get value of textarea
if (trimAll(document.getElementById('tnum').value) === '')
{
alert('Please enter a tracking number!');
}
xhttp.onreadystatechange = function()
{
if (xhttp.readyState == 4 && xhttp.status == 200)
{
document.getElementById('trackinfo').innerHTML = xhttp.responseText;
}
};
xhttp.open("POST", 'http://localhost:8000/cgi-bin/track_project_fxn.py', true);
xhttp.setRequestHeader('Content-type','application/x-www-form-urlencoded');
xhttp.send('tnum='+tnum);
}
function trimAll(sString)
{
while (sString.substring(0,1) == ' ')
{
sString = sString.substring(1, sString.length);
}
while (sString.substring(sString.length-1, sString.length) == ' ')
{
sString = sString.substring(0,sString.length-1);
}
return sString;
}
</script>
</head>
<body bgcolor="33cccc">
<br>
<h3>Tracking</h3>
<form id="trackform">
<textarea form="trackform" id="tnum" rows="10" cols="45" style="resize:none" placeholder="Enter up to 25 tracking numbers, one per line, and separated by commas">
</textarea>
<br><Br>
<input type="button" value="Submit" onclick="track()">
<input type="reset" value="Clear">
</form>
<div id="trackinfo">
</body>
</html>
Python code:
import cgi, cgitb, re
cgitb.enable
form=cgi.FieldStorage()
tnum=form.getvalue('tnum')
unum=tnum.upper()
snum=re.sub('[\s+]', '',unum)
tlist=snum.split(',')
print("Content-type:text/html\r\n\r")
print()
for tnumber in tlist:
<logic>