function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Problem with JavaScript....................Pls Help.?

Hai frnds,


  i have picklist controlls(text,button,radio),and add button on vf page. user select type of controls he want to add on page,when user click on add button then selected control type will display on vfpage,if selected radio button then radio button will add on Vf page.............i am trying with following code but iam not getting pls help.....................



<apex:page id="page">
function addElement()
  var as = document.getElementById('page:fm:pb:choose').value;
          var element = document.createElement("input");
          element.setAttribute("type", as);
          element.setAttribute("value", as);
          element.setAttribute("name", as);
          var ni = document.getElementById('page:fm:pb:myDiv');
<apex:form id="fm">
<apex:pageBlock id="pb">
<B>Select Type:</B>
<apex:selectList id="choose"  size="1"  onchange="change()">
            <apex:selectOption itemvalue="--None--" itemlabel="--None--"/>             
            <apex:selectOption itemValue="Text" itemLabel="Text"/>
            <apex:selectOption itemValue="Button" itemLabel="Button"/>
            <apex:selectOption itemValue="Radio" itemLabel="Radio"/>
  <apex:commandButton onclick="addElement()" value="Add"/>
 <div id="myDiv"> </div>



Thanks in Advance...........






In java script function the following line is not getting the correct id of your div,

var ni = document.getElementById('page:fm:pb:myDiv');


This must be like below:

var ni = document.getElementById('myDiv');


In visual force page , you can access the id of html elements directly.(don't need to give whole hierarchy).