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
FastSnailFastSnail 

Javascript within apex:pageBlockTable Related List ?

Hello,

I have an apex:pageBlockTable that displays a picture for eacg record in the list of record. I want to get the size of each picture using Javascrip width. How do I do that?  I am stuck with the following problem in the code below: the id="AIHURLPicture1" is convey accross all records in the table, so it can not work. How do I get each picture to have a different Id?  Thanks in advance for your support. Have a good weekend, Jerome

 

<apex:pageBlockTable value="{!vehicleList}" var="vehicle" id="vehicletable">
<apex:column>
<img src="{!vehicle.URLPicture1__c}" id="URLPicture1" />
<script>
var URLPict1JS = document.getElementById("URLPicture1");
var pict1 = new Image();
pict1.src=URLPict1JS.src;
var width = pict1.width;
</script>

....

pinoytechiepinoytechie

what you can do as an alternative is to specify the class name within the img tag, i.e:

<img src="{!vehicle.URLPicture1__c}" id="URLPicture1" class="rowImage" />

 and then use document.getElementsByClassName to get the array/list of all the pictures you intend to manipulate, and iterate to it, i.e.:

<script>
  var URLPictJS = document.getElementsByClassName("rowImage");
  for (var i=0; i < URLPictJS.length; i++)
  {
    var pict = new Image();
    pict.src=URLPictJS[i].src;
    var width = pict.width;    
  }
</script>

 NOTE: i haven't tested the posted codes. But this would give you an idea.

FastSnailFastSnail

Thank you; I will test this this afternoon and keep you posted.