1

I've modified the django comment form and noticed that it does not output with an html id. How can I add an html id to the entire form?

I need the id so I can get the value of a radio select in jQuery.

EDIT: I've tried Matthew Schinckel's method below:

var output = $("input[name=rating]:checked").val();
$('#some_div').text(output).fadeIn(500); 

This returns nothing.

HighLife
  • 4,218
  • 7
  • 40
  • 56
  • Why do you need an id on the form? Also, you generally have to write the `
    ` tags yourself in django.
    – Matthew Schinckel Jun 12 '12 at 02:34
  • I'd like to get the value of a radio select with jquery: http://stackoverflow.com/questions/596351/how-can-i-get-which-radio-is-selected-via-jquery – HighLife Jun 12 '12 at 02:35
  • If the name of the tag is unique in the page, just use `$('input[name=radioName]:checked').val()`. – okm Jun 12 '12 at 02:39
  • You don't need the form to have an id for that. This is rather an HTML/Javascript question than a Django question as far as I understand it. Could you post the HTML and tell radio you want ? Thanks in advance for putting some effort in your topic. – jpic Jun 12 '12 at 02:39

1 Answers1

1

Django does put the id of every form element in. You may be able to just use this in jQuery. Or, as okm suggested, use the name attribute.

$('input[name=radioName]:checked').val()

Or, using django's default naming:

$('#id_radioName').val()

(The id may differ if you have multiple forms/formsets on your page).

Matthew Schinckel
  • 35,041
  • 6
  • 86
  • 121
  • I had trouble with this originally, but realized I was removing the form with jQuery before getting the radiobutton value. Thx – HighLife Jun 12 '12 at 04:41