0

I am generating dynamically output for php page via a Python script. During this endavour of mine, I've been also using JavaScript inside my Python script, like so:

print "<script language=\"JavaScript\">"
print "function myF() {"
print "var myField = document.getElementsByName(\"textField\");"
print "var value = myField.value;"
print "}</script>"

Well anyways, I need to get the value somehow into Python, as in assign it to a Python variable. How can I do this?

user1418018
  • 189
  • 1
  • 4
  • 17
  • 2
    I curious to know, how a user can enter a value to the input at the stage the page is still formed on a server? – Teemu Feb 16 '17 at 14:28
  • 1
    Also, see http://stackoverflow.com/questions/10693845/what-do-queryselectorall-getelementsbyclassname-and-other-getelementsby-method . Good to read too:[What is the difference between client-side and server-side programming](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Teemu Feb 16 '17 at 14:34
  • The link doesn't really help with my question (or maybe I misunderstood it), I know how to get the value into JavaScript variable, but how to get it into Python? – user1418018 Feb 16 '17 at 14:37
  • 1
    The first link points out an error in your JS code logic. If user doesn't enter anything, then you've hard-coded the value to your code (or got it from Python), you know it already, shouldn't be hard to hard-code it to Python code too? – Teemu Feb 16 '17 at 14:40
  • Sorry, I worded that poorly. I am listing various simulation results and generating the page. Then each result can be selected via user by JavaScript and this part works fine, so there is user input. My issue is I need to work further with the selected result in Python and I'm not sure how to pass the myField.value into Python variable. Can I write it somewhere with JS and read it through Python? – user1418018 Feb 16 '17 at 14:43
  • 1
    Your approach is totally wrong. Mixing python and php doesn't make any sense. Please explain what do you want to archive. – Raz Feb 16 '17 at 14:47
  • Well, I am working with thousands of objects written in Python, extracting the data and such so I kind of have to use it... – user1418018 Feb 16 '17 at 14:48
  • There can't be any user input before you even load a page to the client ... – Teemu Feb 16 '17 at 14:49

0 Answers0