The 2 options won't work as radio buttons then, though, will they ?



waseem sabjee wrote:
Hi Luigi.
Change your HTML Structure to this

         <div id="choices">
<input type="radio" class="option" id="personaFisica" name="personaFisica" value="0" /> <input type="radio" class="option" id="personaGiuridica" name="personaGiuridica" value="1" />
<!--
notice I wrapped my option in a div and game each option a common class name
-->
        </div>

change your JavaScript to this

        <script>
$(function() { // i prefer using the function wrapper instead of $(document).ready(function() { var choices = $(".option"); // create a reference point note .option is also the class name of my radio inputs
                choices.click(function() { // simple click function
var val = $(this).attr("value"); // retrieve the value attribute of the clicked element
                    if(val == 0) { // if value is 0
                        alert("personaFisica"); // alert whatever
                        $("#mydiv").hide(); // hide what i need to
                        $("#myotherdiv").show(); // show what i need to
                    } else { // if value is not 0
                        alert("personaGiuridica"); // alert whatever
$("#myotherdiv").hide(); // hide what i need to $("#mydiv").show(); // show what i need to }
                });
            });
        </script>

the above should fix your problem


On Mon, May 11, 2009 at 11:20 AM, ciupaz <luigi.zambe...@gmail.com <mailto:luigi.zambe...@gmail.com>> wrote:


    Hi all,
    I have this jQuery snippet to hide a "DIV" block when the user select
    one value of a radio button:

    <script type="text/javascript">
                           $(document).ready(function() {
$("input[name='persona']").change(function() {
                                           if
    ($("input[name='persona']:checked").val() == '0') {
                                                   alert('PersonaFisica');
$('#ragioneSocialeLine').hide(); $('#partitaIvaLine').hide(); $('#sedeLegale').hide(); $('#nomeCognomeLines').show(); $('#generalitaLines').show();
                                           }
                                           else {
alert('PersonaGiuridica'); $('#ragioneSocialeLine').show(); $('#partitaIvaLine').show(); $('#sedeLegale').show(); $('#nomeCognomeLines').hide(); $('#generalitaLines').hide();
                                           }
                                   });

$("input[name='persona']").trigger('change');


    and

    <span class="sportelloamiacque_formfield">
<input type="radio" id="personaFisica" name="persona"
    value="0" /> Persona fisica
<input type="radio" id="personaGiuridica" name="persona"
    value="1" /> Persona giuridica
                                                           </span>

    The problem is that the user "must"click 2 times to obtain that
    functionality in IE8, and it works correctly in Firefox and Chrome.

    How can I solve this strange problem?

    Thanks a lot.

    Luigi


------------------------------------------------------------------------


No virus found in this incoming message.
Checked by AVG - www.avg.com Version: 8.5.325 / Virus Database: 270.12.24/2108 - Release Date: 05/11/09 05:52:00


Reply via email to