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
vanessa veronvanessa veron 

function JS dont work

I have a JS function but it dont work, WHY?

RESULT: into inputText --> undefined
But I have the value outputText into inputText
Thank you

<apex:page standardController="CronTrigger" extensions="BBBB" >
<link rel="ic" type="image/png" href="http://www.voca.com/bull.png"/>

<script type="text/javascript">


function prepopulate(){
var getOPT = document.getElementById("{!$Component.theform.block01.aaa}").value;
document.getElementById("{!$Component.theform.block01.bbb}").value = getOPT;

}
    
</script>

<apex:form id="theform" >  
  <apex:PageBlock id="block01">
   
    <apex:outputText  id="aaa" value="{!$CurrentPage.parameters.nomJobPG2}" /><br />
    Nom Job.:&nbsp;<apex:inputText  id ="bbb" value="{!nomJob}" onclick="prepopulate();return false;"/><br /><br />

  </apex:PageBlock>
  </apex:form>
</apex:page>

Best Answer chosen by vanessa veron
Magdiel HerreraMagdiel Herrera
Just realized you wanted the other way around, here is the update

<apex:page standardController="CronTrigger" extensions="BBBB" >

    <!-- JavaScript Libraries -->
    <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"/>

    <apex:form >
      
      <apex:PageBlock >
        <apex:pageBlockSection columns="1" collapsible="false">
            <apex:pageBlockSectionItem >
                <apex:outputLabel >URLParam (nomJobPG2)</apex:outputLabel>
                <apex:outputText id="aaa" value="{!$CurrentPage.parameters.nomJobPG2}" styleClass="nomJobPG2"/>
            </apex:pageBlockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel >Nom Job.</apex:outputLabel>
                <apex:inputText id="bbb" value="{!nomJob}" onclick="subscribeClickEventHandler('{!$CurrentPage.parameters.nomJobPG2}')" styleClass="bbb"/>
            </apex:pageblockSectionItem>
        </apex:pageBlockSection>        
    
      </apex:PageBlock>
      
    </apex:form>    
        
    <script type="text/javascript">    
        
        /* suggested solution that works */
        function subscribeClickEventHandler(itVal){            
            $(".bbb").val(itVal);
        }
        
        /* Your solution */
        function prepopulate(){
            var getOPT = document.getElementById("{!$Component.theform.block01.aaa}").value;
            document.getElementById("{!$Component.theform.block01.bbb}").value = getOPT;            
        }
            
    </script>    
    
</apex:page>


All Answers

Magdiel HerreraMagdiel Herrera
Hi vanessa,

the outputText visualforce component generates a span tag, so you'll have to fill it using html content rather than value like you'll do it with an input,

also your code here needs some improvements and run away from using generated visualforce ids as it'll easly break your code if the structure changes,

this is what I recommend,
<apex:page standardController="CronTrigger" extensions="testPageController" >

    <!-- JavaScript Libraries -->
    <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"/>

    <apex:form >
      
      <apex:PageBlock >
        <apex:pageBlockSection columns="1" collapsible="false">
            <apex:pageBlockSectionItem >
                <apex:outputLabel >URLParam (nomJobPG2)</apex:outputLabel>
                <apex:outputText id="aaa" value="{!$CurrentPage.parameters.nomJobPG2}" styleClass="nomJobPG2"/>
            </apex:pageBlockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel >Nom Job.</apex:outputLabel>
                <apex:inputText id="bbb" value="{!nomJob}" onclick="subscribeClickEventHandler('{!nomJob}')"/>
            </apex:pageblockSectionItem>
        </apex:pageBlockSection>        
    
      </apex:PageBlock>
      
    </apex:form>    
        
    <script type="text/javascript">    
        
        /* suggested solution that works */
        function subscribeClickEventHandler(itVal){
            $(".nomJobPG2").html(itVal);
        }
        
        /* Your solution */
        function prepopulate(){
            var getOPT = document.getElementById("{!$Component.theform.block01.aaa}").value;
            document.getElementById("{!$Component.theform.block01.bbb}").value = getOPT;            
        }
            
    </script>    
    
</apex:page>



Magdiel HerreraMagdiel Herrera
Just realized you wanted the other way around, here is the update

<apex:page standardController="CronTrigger" extensions="BBBB" >

    <!-- JavaScript Libraries -->
    <apex:includeScript value="//ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"/>

    <apex:form >
      
      <apex:PageBlock >
        <apex:pageBlockSection columns="1" collapsible="false">
            <apex:pageBlockSectionItem >
                <apex:outputLabel >URLParam (nomJobPG2)</apex:outputLabel>
                <apex:outputText id="aaa" value="{!$CurrentPage.parameters.nomJobPG2}" styleClass="nomJobPG2"/>
            </apex:pageBlockSectionItem>
            <apex:pageblockSectionItem >
                <apex:outputLabel >Nom Job.</apex:outputLabel>
                <apex:inputText id="bbb" value="{!nomJob}" onclick="subscribeClickEventHandler('{!$CurrentPage.parameters.nomJobPG2}')" styleClass="bbb"/>
            </apex:pageblockSectionItem>
        </apex:pageBlockSection>        
    
      </apex:PageBlock>
      
    </apex:form>    
        
    <script type="text/javascript">    
        
        /* suggested solution that works */
        function subscribeClickEventHandler(itVal){            
            $(".bbb").val(itVal);
        }
        
        /* Your solution */
        function prepopulate(){
            var getOPT = document.getElementById("{!$Component.theform.block01.aaa}").value;
            document.getElementById("{!$Component.theform.block01.bbb}").value = getOPT;            
        }
            
    </script>    
    
</apex:page>


This was selected as the best answer
vanessa veronvanessa veron
Thank you!!!