开发者

JavaScript Dynamic Adding of elements

开发者 https://www.devze.com 2023-02-15 23:30 出处:网络
Please look at the following code mydiv1.innerHTML=mydiv1.innerHTML + \'<label>*Functional Area:<span class=\"small\">Enter Company Name</span></label><input type=\"text\

Please look at the following code


mydiv1.innerHTML=mydiv1.innerHTML + '<label>*Functional Area:<span class="small">Enter Company Name</span></label><input type="text" name="FunctionalArea_"'+counter1+' id="company" /><label class="spacing">*Experience:<span class="small">Number of years</span></label><select name="Exp_In_FA_"'+ counter1 +' id="experience"><option>1</option><option>2</option><option>3</option><option>4</option><option>5</option><option>morethan 5</option</select><input type="button" value="Add" id="bt1" onclick="generate()" style="font-size:8pt;height:25px;width:55px"/>' 

Now the above javascript code is called properly and new elements get embedded at the desired location开发者_如何学Go. But the problem is that when these values are passed to servlet, i am unable to retrieve Exp_In_FA_0 by using request.getParameter("Exp_In_FA_0"). It simply returns NULL. Please correct me where i am doing wrong? Sorry that i am unable to post the code in multiple lines. The code tag takes everything in single line only


Try using Firebug (or similar tools) to see the actual genearted code (using the "Inspect Element") feature.

You might want to confirm the name, the form in which the element is added etc.


Have a read here https://stackoverflow.com/search?q=innerhtml+form+not+passed

and

http://domscripting.com/blog/display/99

First of all, use the DOM to create a block level element—such as a div—using createElement. Then update the innerHTML property of this newly-created element. Finally, insert the updated element into the document using a DOM method like appendChild or insertBefore:

var newdiv = document.createElement("div");
newdiv.innerHTML = xhr.responseText;
var container = document.getElementById("container");
container.appendChild(newdiv);


[...] new elements get embedded at the desired location.

Check whether the name attribute of the new element laso OK in the resulting HTML document. You can do this in Firefox with selecting your input box and the surrounding HTML and from the context menu choosing "Yiew source of selection". - Or you can use Google Chrome's "Inspect" feature to watch the element.

0

精彩评论

暂无评论...
验证码 换一张
取 消