The selection form consists of the choice of the operator and the amount. For example

СТРАНА: НОМЕР: ID: Россия 8503 1 3353 2 Украина 2855 1 3855 2 

There is a drop-down list, and a radio button, how can you make it so that when choosing a country and a radio butane id the number 1 or 2 is displayed?

 <select id="country_id" name="country" onchange="show_country()"> <option value="1">Россия</option> <option value="2">Украина</option> </select> <input name="tariff" type="radio" onSelect="" value="" checked /> <input name="tariff2" type="radio" onSelect="" value="" /> function show_country() { var countryId = ge('country_id').value; var short_number_one = ["","8503","2855"]; var short_number_one = ["","3353","3855"]; ge('number').innerHTML = short_number[countryId]; } Т 
  • I don’t know, I understood the question correctly, but I’ll suggest this option: radio buttons, you can insert directly into <option>, and then, using jQuery, add the elements you need. In this case, good help jquery-docs.ru - Sergey Kashurin
  • I think to do if the first button, then the first array if the second button is the second array, but as in JS you need to get these buttons to look ... - avengerweb
  • Let me show you one interesting little idea : kashurin.tmweb.ru/?L=78, the point is that you can make a couple of such lists, pay attention to the structure, above, you can save intermediate results in input type = "hidden", to display the following menus and so on. Perhaps useful. - Sergey Kashurin
  • how to handle a radiobutton event? - avengerweb
  • processed as onclick thanks everyone. - avengerweb

1 answer 1

How to handle events with input bad tone. And this, to put it mildly, can lead further to very terrible mistakes. I advise you to simultaneously put on onChange and onInput

On jQuery, it looks like this:

 $('input[type=radio]').on('change input', function () { if ($(this).prop('checked')) { // Возвращает boolean // Ваш код } }); 

On the native bit more code, but the essence is the same

 var radioEls = document.querySelectorAll('input[type=radio]'); for (var i = 0, ii = radioEls.length; i < ii; ++i) { radioEls[i].addEventListener('change', onChangeRadioBtn, false); radioEls[i].addEventListener('input', onChangeRadioBtn, false); } function onChangeRadioBtn(evt) { if (this.checked) { // Ваш код здесь } } 

Although for good, here you will also need to implement a cross-browser addEventListener if older browsers are supported.