简体   繁体   中英

JQuery dialog box prevents getting values from radio buttons

I've been creating a webpage using Javascript, JQuery, and the FlatUI framework, and I've hit a bit of a roadblock.

Using this JQuery code:

$( "#db" + category ).dialog( "open" );

I open the following dialog box:

    <div id="dbHome" class="dialogBox">
        <form id="formHome" action="javascript:void(0);" onsubmit="submitData('Home', 'radio')">
            <p>
                What type of home do you live in?
            </p>
            <label class="radio" for="radioHome1">
            Unit / Flat / Apartment
            <input type="radio" id="radioHome1" name="inputHome" value="Unit / Flat / Apartment" data-toggle="radio" checked="">
            </label>

            <label class="radio" for="radioHome2">
            Town House / House
            <input type="radio" id="radioHome2" name="inputHome" value="Town House / House" data-toggle="radio">
            </label>

            <input type="submit" class="btn btn-primary btn-large  btn-info" style="float: right;" value="Submit">

        </form>
    </div>

The dialog box opens without issue. However, when I click the submit button (and execute "submitData()", the function is unable to retrieve the value that the user selects from the radio buttons. There is more to this issue though: If the user doesn't click a radio button, and instead leaves the default "checked" button untouched, the function is able to retrieve the value. But if the user selects a different radio, then selects the default one again, the function will still return "undefined" when asked to get the value.

The function in question executes the following code:

function submitData(category, inputType)
{
    // Get the index (to search in the array)
    var key;

    key = $("#form" + category + " input[name=input" + category + "]:checked").val();

    alert("KEY: " + key); // Prints "undefined" if the user makes any input.
}

I've tried countless different code to retrieve values from radios. None of it has worked.

I hope I've provided enough information here, and thank you so much in advance.

It wasn't my code that was causing issues. It was an external file (provided by the framework) that was interfering.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM