views:

57

answers:

2

Hello,

I have a via with some jQuery function to get value from HTML element (to access element available and element not yet available). On of these element is a dropdown, when I select a value an another vue is added in the bottom of the page in a div. When I try to access an element added by this view, I received "undefined". What can I do ?

In the div #ProductDetail, I add element. and it's these elements I can't access.

Update 1 (trying to be more clear) - I have a page with some HTML element (several in put, a dropdown) - I have javascript method available on this page to access HTML element present or not yet present on this pahge - I have a - When I selected a value via the dropdown, I receive a view, this view is added to the . - When I try to access the HTML element present at the origin that'd work - When I try to access the HTML elemetn added in the that's not work, I received "undifined element"

$.ajax({

type: "POST",
url: "/Product/Edition",
data: {
    id: getId()
},
success: function(data) {
    $("#divDisplayDialogProduct").html(data);
    $('#ProductType').change(function() {
        $.ajax({
            type: "POST",
            url: "/Product/ShowDetail",
            data: { id: $('#ProductType').val() },
            success: function(data) { $("#ProductDetail").html(data); },
            error: function(XMLHttpRequest, textStatus, errorThrown) { }
        })
    });
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
}

})
A: 

If #ProductDetail is your select tag, I believe you need to access the selected value like this:

$("#ProductDetail option:selected").val();
Mike Thomsen
Wrong. When called on a `<select>` element, `val` will give the value of the selected option. http://api.jquery.com/val/
SLaks
+2  A: 

Base on your comment response:

You still need the # to reference an element by ID like this:

function getDVDNameVO() { 
  return $('#MyNewElement').val(); 
}
Nick Craver
How can I missed that ! :( You are right ! Thanks
Kris-I