I’m trying to get a form (provided in HTML form from a callback) after adding it to already present content. Adding it presents no issues and the form shows up properly. It is provided (as HTML) by the callback with the id= (placeid + “commentinput”) and added to the page. However, trying to do $(placeid + “commentinput”) does not return a proper jQuery element (for example, the alert(form.tagName) is supposed to return “FORM” but is always undefined instead).
function click_comment1(urlstr, id) { $.ajax({url: urlstr,success: success_on_get_form(urlstr, id)}); }
function success_on_get_form(urlstr, placeid) {
return function (val) {
$("#" + placeid + "newcomment").html(val.replace("comments_body","body"));
$("#pup").html($("#" + placeid + "comments").html());
var form = jQuery("#" + placeid + "commentinput");
var func = submit_comment(urlstr, placeid);
alert(form.id);
form.bind('submit',func);
} }
I’ve tried every other form of selection I know of at this point (basically, .children(). I’m new to jQuery). I’ve been hacking at this problem in various forms helplessly for 4 hours now. I’d appreciate any help, thank you.
<form action="" enctype="multipart/form-data" id="1commentinput" method="post">...</form>
This is the return from the callback; the middle part is omitted for space.
The #pup element seen is a popup as provided with this.
“#” + placeid + “newcomment” is a div within “#” + placeid + “comments”. These first 2 calls executing seemingly properly and render the callback provided form in the popup as desired.
The intent with all of this is to add a form to this popup, which is then used to make a second callback.
Your problem most likely boils down to the fact that you are using invalid character to start your element ID..
Change it to start with a valid character and it should work.
http://www.w3.org/TR/html4/types.html#type-id