Log in

View Full Version : Unable to function Radio Button & Add Text Area in JS



tvd
05-12-2007, 03:00 PM
Hello,

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 :



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.


Regarding TExt Area:-
Based on the above form, I want to add a TextArea via another function. The code is :-


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

This gives me error on textTA.innerHTML line. If this is incorrect, then how do i add contents to the text area.

You all experts will be able to help me out.

Thank

TVD

jscheuer1
05-12-2007, 03:31 PM
Although this varies by browser (some may excuse the mistake) a textarea has no innerHTML property. The property you want in the case of a textarea is its value.