I am trying to add 2 RadioButtons in a form in js dynamically. I can see 2 radiobutttons, but no text. On clicking them, their is no selection. One of them is selected. I need to retrive their vakue on button click. The form is added in a div which is present in html form (that is not dynamically created). Form & all other elements are created dynamically & appended to div elemetn whch is present in html. The code is :
Expand|Select|Wrap|Line Numbers
- var miles=document.createElement("input");
- miles.setAttribute("type", "radio");
- miles.setAttribute("id", "miles");
- miles.setAttribute("value", "miles");
- miles.setAttribute("checked", "true");
- miles.setAttribute("name", "units");
- var km=document.createElement("input");
- km.setAttribute("type", "radio");
- km.setAttribute("id", "km");
- km.setAttribute("value", "km");
- km.setAttribute("checked", "false");
- km.setAttribute("name", "units");
- var getVal=function(){
- scaleUnits=document.forms['dynamicForm'].elements['radio'].value;
- alert(scaleUnits);
- driveFrom=document.forms['dynamicForm'].elements['fromTxt'].value;
- driveTo=document.forms['dynamicForm'].elements['toTxt'].value;
- GetDirections(driveFrom, driveTo);
- } //this sets up a function in the same scope as the onclick assignment that will use it.
- getDirectionsBtn.onclick=getVal; //this assigns the function to the element.
Based on the above form, I want to add a TextArea via another function. The code is :-
Expand|Select|Wrap|Line Numbers
- function DoAlert(text) {
- var d=document.getElementById("directDIV");
- var e=document.getElementById("dynamicForm");
- d.style.visibility="visible";
- // var dynamicForm=document.createElement("form");
- // dynamicForm.setAttribute("id", "dynamicForm");
- // dynamicForm.setAttribute("runat", "server");
- var textTA=document.createElement("textarea");
- textTA.setAttribute("id", "textTA");
- textTA.setAttribute("overflow", "auto");
- textTA.setAttribute("rows", "30");
- textTA.innerHTML=text;
- e.appendChild(textTA);
- // d.insertBefore(dynamicForm, lbl);
- }
Help me guys.
Thank
Trupti