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
ShuchiMShuchiM 

Visualforce popup in apex:repeat

Hi, 

 

I am trying to get a lookup behaviour on my VF page. I have an image that shows a popup, gets first name , last name from the user, creates a contact and then displays the ID in a input text box. I have this behavior repeated for many rows, ie. i have a apex:repeat and each row has an image button which calls this popup and calculates the id, and an input text box that displays the created id.

 

The problem is, how do I get the id of the input text field from the repeat row? My image and input text field are in the same row, but how do i find out which row's image did i click?

 

Regards

Shuchi

Best Answer chosen by Admin (Salesforce Developers) 
Damien_Damien_

Try putting the Id of the object or something else like that dynamic as part of the id of the field and then passing that through the javascript onclick method.

 

<script>
	function myJSMethod(passedId)
	{
		var something = document.getElementById(passedId);
	}
</script>

<apex:repeat value="{!myList}" var="myObj">
	<apex:image onclick="myJSMethod('{!myObj.Id}');" />
	<input type="text" id="mytextbox{!myObj.Id}" />
</apex:repeat>

 

All Answers

Damien_Damien_

Try putting the Id of the object or something else like that dynamic as part of the id of the field and then passing that through the javascript onclick method.

 

<script>
	function myJSMethod(passedId)
	{
		var something = document.getElementById(passedId);
	}
</script>

<apex:repeat value="{!myList}" var="myObj">
	<apex:image onclick="myJSMethod('{!myObj.Id}');" />
	<input type="text" id="mytextbox{!myObj.Id}" />
</apex:repeat>

 

This was selected as the best answer
ShuchiMShuchiM

Good idea ! Thank u Damien. I used .closest() jquery method to get the closest element since they were both in the same row.