There is a slider that pulls out images from the database, switching between images should be done by navigating through radio buttons using CSS 3. I debug everything, all that remains is to transfer the “checked” value for input, and transfer the entire slider HTML frame in the same way:

<?php ... echo ... '<div id="slider"> <input type="radio" id="button_1" name="radio_buttons" checked /> <input type="radio" id="button_2" name="radio_buttons" /> ... <img src="'.$foto['foto_1'].'"> ... <img src="'.$foto['foto_2'].'"> ... </div>';}} ?> 

If I change the type of the 1st button to "checkbox", then the "checked" attribute will be passed without problems, but then I will not be able to switch m / s pictures, but I don’t know how to transfer it to "radio" ?! In my opinion, this is some kind of phantom bug .. the network did not find any specific syntax for radio buttons

Ready to "be a fool for 5 minutes" in your eyes. Thank!

* marked with dots pieces of code that go before and after .. and have no effect on the transfer of "checked" - tested empirically

Closed due to the fact that off-topic participants rjhdby , AK , user194374, Vadim Ovchinnikov , aleksandr barakin Jan 31 '17 at 17:10 .

It seems that this question does not correspond to the subject of the site. Those who voted to close it indicated the following reason:

  • "The question is caused by a problem that is no longer reproduced or typed . Although similar questions may be relevant on this site, solving this question is unlikely to help future visitors. You can usually avoid similar questions by writing and researching a minimum program to reproduce the problem before publishing the question. " - rjhdby, AK, Community Spirit, Vadim Ovchinnikov
If the question can be reformulated according to the rules set out in the certificate , edit it .

  • And in the final page code, what? checked present? - rjhdby
  • rjhdby, no, unfortunately, the "checked" client is not transmitted, BUT I partially solved my task by putting a patch on jQuery: var check = document.getElementsByName ('radio_buttons'); if (! check [1] .checked) check [1] .checked = true; - dance king
  • You understand that magic does not exist? If you forcibly set checked in a string variable, then it was typed in html. There are two options, in fact: 1) You have a wrongly formed string (it’s also in a loop, yes?) - enter the intermediate variable $string='bla-bla';var_dump($string);echo $string; and make sure everything is ok. 2) javascript hurts you. Look in your functions / dependencies that can capture this attribute. - rjhdby
  • rjhdby, at the expense of magic you are right, as are right at the expense of withdrawal in a cycle! ;) I had many such inputs and they were for each output div, from which the slider was already launched; I added ID's of these divs to the output for each input and it all worked for me, even my jQuery patch was not needed, because it worked only for the 1st output div! I have already begun to sin in his direction .. but you guided me on the right path! Apparently, the script did not understand for which particular div it is necessary to put the value "checked" .. in general, Thank you BIG !!! I spent more than one day on this .. - dance king
  • one
    it happens :) In general, if suddenly something behaves incorrectly, take it as a rule to insert var_dump through the line with the output calculated above. Oooooochen helps :) - rjhdby

1 answer 1

With such choices as gender - the easiest way to write with pens is just a pair of input with constant values ​​that are independent of DB.

 <input type="radio" name="radio" value="yes" class="radio" <?php if (isset($_POST['radio']) && $_POST['radio'] == 'yes'): ?>checked='checked'<?php endif; ?> /> Yes <input type="radio" name="radio" value="no" class="radio" <?php if (isset($_POST['radio']) && $_POST['radio'] == 'no'): ?>checked='checked'<?php endif; ?> /> No 
  • ultimatum, thanks for an interesting example;) it’s just not a bit of what I would like .. my fault - the question was somewhat vague and I didn’t put the code (I wanted to put the emphasis on "checked"), I have much more input than 2, and I only send the links to the photo by POST, but I wanted to display "checked" through echo. While I solved the problem with a piece of jQuery insert, I still can't understand why the "checked" is not set in the usual way ?! - dance king