|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
python cgi question
I'm trying to modify a python cgi script which appears to recursively call on itself everytime an action is taken. I have added some radio buttons which work when I have a final "submit" button but I want the action to occur when the radio buttons are selected (using onClick ?). But when I try the onClick syntax, the cgi doesn't work. Any help would be appreciated.
Here's my code with the submit button. This works: Code:
def htmlldcoord():
print('''\
<form action="%s" method="get">
Move Cam: <input type="radio" checked name="mode" value="move_cam">
<br>
P1 Input: <input type="radio" name="mode" value="p1_in">
<br>
P2 Input: <input type="radio" name="mode" value="p2_in">
<input type="submit" name="submit">
</form>
''' % SCRIPT)
Here's my code with onClick. This does not work: Code:
def htmlldcoord():
print('''\
<form action="%s" method="get">
Move Cam: <input type="radio" checked name="mode" value="move_cam" onClick="%s">
<br>
P1 Input: <input type="radio" name="mode" value="p1_in" onClick="%s">
<br>
P2 Input: <input type="radio" name="mode" value="p2_in" onClick="%s">
</form>
''' % SCRIPT)
|
|
#2
|
|||
|
|||
|
It's doing string substitution - the first parameter (SCRIPT) goes to the first %s
Code:
>>> "test %s test" % "hi" "test hi test" When you put a second %s in the string (for the onClick addition), you get... Code:
>>> "test %s test %s test" % "hi"
Traceback (most recent call last):
File "<pyshell#15>", line 1, in -toplevel-
"test %s test %s test" % "hi"
TypeError: not enough arguments for format string
You could change the bit at the end to be: Code:
% (SCRIPT, SCRIPT) |
|
#3
|
|||
|
|||
|
I've put in the added SCRIPTS at the bottom so the page loads correctly. However, when I click on a radio button, the script still isn't being reloaded. Instead an "error on page" message is flashed in the status bar.
![]() |
![]() |
| Viewing: Dev Shed Forums > Programming Languages > Python Programming > python cgi question |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|