I’ve got a simple HTML page with a hidden field on it. I display a DIV which has a button on for the user to click – when they do that, I want to update the hidden field on the main page.
At the moment, I have this in my main HTML (in a CGI file):
print "<td><input type=\"hidden\" id=\"mailUpdate\"></td></tr>";
I have this (in a javascript module accessed by the onClick for a button in the div):
var updMail = document.getElementById("mailUpdate");
updMail.value = 1;
but when I try read this (in the same CGI file as above) with this:
formData = cgi.FieldStorage()
doUpd = formData.getvalue("mailUpdate")
if (doUpd == 1):
print "Maint button - doing update"
‘doUpd’ is never getting any value.
Hope this makes sense – any ideas?
You issue lies in the expression
(doUpd == 1):You are comparing doUpd, which is a string, to an integer, 1. This will always beFalse. Changing to(doUpd == '1'):should fix your issue.Also, You need to add the
nameto the input so that it will come across with the form.