[英]How to get value of javascript variable in python variable in Python-CGI script
I want to take the value of javascript variable into python variable. 我想将javascript变量的值转换为python变量。
This is Python-CGI script which displays a selection box and selected value appears on the page. 这是Python-CGI脚本,它显示一个选择框,并且所选值出现在页面上。 But I want to take selected value in python variable.
但是我想在python变量中采用选定的值。
#!/usr/bin/python2.7 -u
import time, sys, os
# Import modules for CGI handling
import cgi, cgitb
sys.stdout.write('Content-Type: text/html;charset=utf-8\n')
print "\n\n"
print "<html>"
print "<body>"
rows = ['1.1.1.1', '2.2.2.2', '3.3.3.3']
print "<script>"
print "function showData() {"
print "var sel = document.getElementById('combo');"
print "var value = sel.value;"
print "var text = sel.options[sel.selectedIndex].text;"
print "document.getElementById('secondP').innerHTML=text;}"
print "</script>"
print '<form name="comboform">'
print '<select name="comboselect" onchange="showData()" id="combo">'
for row in rows:
print "<option value='%s'>%s</option>"%(row,row)
print "</select>"
print "</form>"
print '<p id="secondP"> </p>'
# HERE I WANT TO TAKE VALUE OF SELECTED IP ADDRESS (var value) IN PYTHON VARIABLE
# selected_ip_adr = value #something like this where value has selected ip address
# NEED TO PASS THE SAME TO ANOTHER SCRIPT
sys.stdout.flush()
print "</body>"
print "</html>"
It would be great if someone can suggest a work-around to achieve this. 如果有人可以提出解决方法以实现此目标,那将是很好的。
I was able to resolve it with following code and multiple pages: 我可以使用以下代码和多个页面来解决它:
# Create instance of FieldStorage
form = cgi.FieldStorage()
op = form.getvalue('combo')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.