views:

3582

answers:

4

Here's a code snippet. . .

<form name="FinalAccept" method="get"><br>

<input type="radio" name="YesNo" value="Yes" onclick="/accept"> Yes<br>

<input type="radio" name="YesNo" value="No" onclick="/accept"> No<br>

Clearly, what I'm trying to do is call the routine linked to /accept when the user clicks on the radio button.

I know the routine is working because I call the same routine from another place in the program.

I'm trying to run it locally using google appserver. Is there something I'm missing?

Thanks

+2  A: 

Your onClick event is expecting some javascript code:

onclick="SomeJavaScriptCode"

More here: http://www.w3schools.com/jsref/jsref_onClick.asp

So, you should be doing something like this:

onClick="myfunction('my value');"

EDIT: It looks like you want to go to a URL when the user clicks either "yes" or "no". To do that, you can try this little bit of javascript code:

onClick="location.href='http://www.example.com/accept';"
onClick="location.href='http://www.example.com/decline';"

Now, if you want to submit the form automatically when the user clicks either "yes" or "no", then do what Benry suggests:

onClick="this.form.submit();"

Hope this helps.

BoltBait
where do you define that function? even if I put in nonsense, it doesn't produce an error. It's like it never gets called. is there a way to make an onclick call a cgi script? I'm not using javascript for this.
Baltimark
+1  A: 

You're probably thinking of action= for the form element. onClick would just fire a javascript function.

jamtoday
+2  A: 

If you want to submit the entire form when the user clicks on a radio button, then try this:

<form name="FinalAccept" method="get" action="accept"><br>
<input type="radio" name="YesNo" value="Yes" onclick="this.form.submit();"> Yes<br>
<input type="radio" name="YesNo" value="No" onclick="this.form.submit();"> No<br>
</form>

Plus, if you want to make your UI a little more user friendly, change it to this:

<form name="FinalAccept" method="get" action="accept"><br>
<input id="rYes" type="radio" name="YesNo" value="Yes" onclick="this.form.submit();">
<label for="rYes">Yes</label><br>
<input id="rNo" type="radio" name="YesNo" value="No" onclick="this.form.submit();">
<label for="rNo">No</label><br>
</form>

This will make the text "Yes" and "No" as clickable labels for their radio buttons. The user can click the label to select the radio button.

Benry
A: 

OK -- I should have been clearer; I'm not using javascript at all. nothing philosophical, just trying to stay consistent.I thought there might be a way to do this without javascript. It's all in python with google appserver.

I've used "action=" for this form. I wanted to have an action take place when the user clicked the radio button, instead of having to click submit, but that's all right.

Benry -- thanks for the tip on using "id" and "for". I have very little html background.

Baltimark
If you're using onclick on a HTML element, you're using javascript.I see your question is a year old, so I hope you used that time to learn the difference between client side (html+javascript) and serverside (python appserver or whatever you're using) and how they interact. Read how HTTP works (because that's how they interact).
mcv