0

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) {
}

})
4
  • 2
    Which part doesn't work? It's unclear from the question, may want to re-read and edit the question. Commented Mar 17, 2010 at 19:37
  • can you attach the html? Commented Mar 17, 2010 at 19:38
  • 1
    Where are you trying to get the value? every where you are setting the value instead of getting it in your code! Commented Mar 17, 2010 at 19:41
  • @Nick Craver this line success: function(data) { $("#ProductDetail").html(data); }, add some HTML element (an <input type="text" id="MyNewElement" /> in DIV ProductDetail, I see it. But when I try to do this : function getDVDNameVO() { return $('MyNewElement').val(); } I received undifined Commented Mar 17, 2010 at 19:43

2 Answers 2

2

Base on your comment response:

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

function getDVDNameVO() { 
  return $('#MyNewElement').val(); 
}
Sign up to request clarification or add additional context in comments.

Comments

0

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

$("#ProductDetail option:selected").val();

1 Comment

Wrong. When called on a <select> element, val will give the value of the selected option. api.jquery.com/val

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.