简体   繁体   中英

jQuery accessing form values in a div that has been loaded through $.ajax

I am loading a page into a div via jQuery in install1 . Now the page that install1 gives me contains a few radio buttons the likes of:

<input name="ostype" type="radio" value="solaris">
<input name="ostype" type="radio" value="windows">

Now, I am trying to access the selected value in install2 .

Here is the JavaScript code for the two functions:

function install1() {
  $("#installer").html("<div align='center'><img src='modules/servers/flosoftdedicated/images/ajax/loading-warning.gif' border='0' alt='' /><br />Loading...</div>"); 
  $.ajax({
    type: 'GET',
    url: 'clientarea.php',
    data: 'action=productdetails&id=' + $('#serverid').val() + '&modop=custom&a=installgetos&step=1',
    timeout: 10000,
    success: function(data){
        $("#installer").html(data);
        },
    });
}
function install2() {
  $("#installer").html("<div align='center'><img src='modules/servers/flosoftdedicated/images/ajax/loading-warning.gif' border='0' alt='' /><br />Loading...</div>"); 
  $.ajax({
    type: 'GET',
    url: 'clientarea.php',
    data: 'action=productdetails&id=' + $('#serverid').val() + '&modop=custom&a=installgetos&step=2&ostype=' + $("input[name='ostype']:checked").val(),
    timeout: 10000,
    success: function(data){
        $("#installer").html(data);
        },
    });
}

In your install2 function you are resetting the content of the install2 div by calling $("#installer").html("<div align='center'>... and removing the inputs.

Remove the first line in the install2 function.

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