#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    5
    Rep Power
    0

    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. #2
  3. No Profile Picture
    Contributing User
    Devshed Novice (500 - 999 posts)

    Join Date
    Nov 2003
    Posts
    624
    Rep Power
    35
    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)
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Nov 2004
    Posts
    5
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo