Get value of radio button [SOLVED]

sauber89 05 Feb, 2013
Hi,

How to get value of radio buttom (id="categorie") and put it in a text box field (id="location") with a "Load JS" script placed after "Show HTML".

Based on this post, I have obtained the following code:

window.addEvent('domready', function() {
  $$('input[name=categorie]').addEvent('click', rekenen1);
});

function rekenen1(){
  $('location').value = $('input:radio[name=categorie]:checked').val();
}


However, the value of "categorie" does not display into the "location" field. I guess the there is an error into the function "rekenen1()", but I don't know which one.

Thanks.
Max_admin 07 Feb, 2013
Hi,

I think that you have missed JQuery with mootools code, plz try this:


window.addEvent('domready', function() {
  $$('input[name=categorie]').addEvent('click', rekenen1);
});

function rekenen1(){
$('location').set('value', $('categorie').get('value'));
}


Regards,
Max
Max, ChronoForms developer
ChronoMyAdmin: Database administration within Joomla, no phpMyAdmin needed.
ChronoMails simplifies Joomla email: newsletters, logging, and custom templates.
sauber89 10 Feb, 2013
Thanks for your reply. However, it doesn't work. Please find my HTML code for the radio button.

<div class="ccms_form_element cfdiv_radio" id="categorie_container_div" style=""><label for="categorie">Catégorie Bus*</label><input type="hidden" name="categorie" value="" alt="ghost" /><div style="float:left; clear:none;">
<input type="radio" name="categorie" id="categorie_0" title="" value="m1" class="validate['required']" />
<label for="categorie_0">M1</label>
<input type="radio" name="categorie" id="categorie_1" title="" value="m3" class="validate['required']" />
<label for="categorie_1">M3</label>
<input type="radio" name="categorie" id="categorie_2" title="" value="m4" class="validate['required']" />
<label for="categorie_2">M4</label>
<input type="radio" name="categorie" id="categorie_3" title="" value="m5" class="validate['required']" />
<label for="categorie_3">M5</label>
</div><div class="clear"></div><div id="error-message-categorie"></div></div>


Any Idea?
GreyHead 10 Feb, 2013
Hi sauber89,

Please try:
window.addEvent('domready', function() {
  $$('input[name=categorie]').each(function(item) {
    item.addEvent('click', function() {
      $('location').value = $$('input[name=categorie]:checked')[0].value;
    });
  });
});
it seems to work correctly.

Bob
This topic is locked and no more replies can be posted.