Results 1 to 2 of 2

Thread: Unable to function Radio Button & Add Text Area in JS

  1. #1
    Join Date
    May 2007
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Unable to function Radio Button & Add Text Area in JS

    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 :

    Code:
       
        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 :-
    Code:
    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

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    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.
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •