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
SfdcBlueFishSfdcBlueFish 

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">
<script>
function addElement()
{
  var as = document.getElementById('page:fm:pb:choose').value;
  alert(as);
  
  if(as=='Text')
   {
         
          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');
         
          ni.appendChild(element);
   }
}
</script> 
<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:selectList>
        
  <apex:commandButton onclick="addElement()" value="Add"/>
  
 <div id="myDiv"> </div>
</apex:pageBlock>
</apex:form>
</apex:page>

 

 

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

 

SfdcBlueFish

Alok_NagarroAlok_Nagarro

Hi,

 

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).