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
JamesSSJamesSS 

ids values isn't putting in Text boxes

My code:

<apex:page sidebar="false" showheader="false">
<apex:includeScript value="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" />
<script>
$(document).ready(function() {
$('input[id^="textInput"]').val('news here!');
});
</script>
<apex:form>
<apex:inputText id="textInput1"/>
<apex:inputText id="textInput2"/>
<apex:inputText id="textInput3"/>
</apex:form>
</apex:page>

 

In above code, on page load,jquery value isn't put in the textboxes.Is any error is in my code? 

Avidev9Avidev9

To select VF component using jquery you need ENDS WITH selector

 

Something like

 

$('[id$="textinput1"]').val('My Value');

 

JamesSSJamesSS

Thanks Avi.Still its not working.

In my expected output is 

all input texts with an attribute id that starts with 'textInput ' and puts text('My Value') in them.

 

But your above code is working only for id that starts with 'textInput1 '.Is it possible to get the above my expected output?

Avidev9Avidev9

Well salesforce has its own algorithm to generate Ids. It generraly adds a prefix to the Id.

Use style class instead

<apex:inputText id="textInput1" styleclass="myInput"/>
<apex:inputText id="textInput2" styleclass="myInput"/>
<apex:inputText id="textInput3" styleClass="myInput"/>

$('.myInput').val('My Text');