By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
464,545 Members | 851 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 464,545 IT Pros & Developers. It's quick & easy.

Unable to function Radio Button & Add Text Area in JS

P: 13
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 :

Expand|Select|Wrap|Line Numbers
  1.  
  2.     var miles=document.createElement("input");
  3.     miles.setAttribute("type", "radio");
  4.     miles.setAttribute("id", "miles");
  5.     miles.setAttribute("value", "miles");
  6.     miles.setAttribute("checked", "true");
  7.     miles.setAttribute("name", "units");
  8.  
  9.     var km=document.createElement("input");
  10.     km.setAttribute("type", "radio");
  11.     km.setAttribute("id", "km");
  12.     km.setAttribute("value", "km");
  13.     km.setAttribute("checked", "false");
  14.     km.setAttribute("name", "units");
  15.  
  16.     var getVal=function(){
  17.         scaleUnits=document.forms['dynamicForm'].elements['radio'].value;
  18.         alert(scaleUnits);
  19.         driveFrom=document.forms['dynamicForm'].elements['fromTxt'].value;
  20.         driveTo=document.forms['dynamicForm'].elements['toTxt'].value; 
  21.         GetDirections(driveFrom, driveTo);
  22.     }  //this sets up a function in the same scope as the onclick assignment that will use it.
  23.     getDirectionsBtn.onclick=getVal;  //this assigns the function to the element.
  24.  
Regarding TExt Area:-
Based on the above form, I want to add a TextArea via another function. The code is :-
Expand|Select|Wrap|Line Numbers
  1. function DoAlert(text) {
  2.     var d=document.getElementById("directDIV");
  3.     var e=document.getElementById("dynamicForm");
  4.     d.style.visibility="visible";
  5. //     var dynamicForm=document.createElement("form");
  6. //    dynamicForm.setAttribute("id", "dynamicForm");
  7. //    dynamicForm.setAttribute("runat", "server");
  8.  
  9.     var textTA=document.createElement("textarea");
  10.     textTA.setAttribute("id", "textTA");
  11.     textTA.setAttribute("overflow", "auto");
  12.     textTA.setAttribute("rows", "30");
  13.     textTA.innerHTML=text;
  14.  
  15.     e.appendChild(textTA);
  16. //    d.insertBefore(dynamicForm, lbl);    
  17. }
This gives me error on textTA.innerHTML line. If this is incorrect, then how do i add contents to the text area.

Help me guys.

Thank

Trupti
May 12 '07 #1
Share this Question
Share on Google+
1 Reply

pbmods
Expert 5K+
P: 5,821
This gives me error on textTA.innerHTML line. If this is incorrect, then how do i add contents to the text area.
Expand|Select|Wrap|Line Numbers
  1. textTA.value = text;
  2.  
May 12 '07 #2

Post your reply

Sign in to post your reply or Sign up for a free account.