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
suneilchetlursuneilchetlur 

Pop up dialogue box on visualforce page

Hello there,

 

I have a visualforce page which contains a table displaying opportunitylineitemss of a particular opportunity.

I have a couple of fields in the table in the visualforce page which i want to compare upon saving and if they are not having the same values then

I have a requirement which is that everytime i click save button in the page i want a pop up which says these two fields have different values confirm whether i want to save (yes or no) .

 

note-i have a controller in place from which the values are taken and displayed in the visualforce page. 

 

Any idea how to go about this problem?

 

thanks in advance

suneil

NaishadhNaishadh

You want to compare opplineItem value with opportunity value or just you want to compare opplineItem value in popup only?

 

In both the case you can use javascript for  validation and actionFunction for submit. 

prageethprageeth

Hi suneilchetlur;

You can do a javascript validation as below. I assume that youhave a method named "saveData()" in your controller to save data.

 

Controller: 

 

public class MyClass{

public void saveData() {

//do something

}

} 

 Page:

 

<apex:page Controller="MyClass">

<script>

function validate(obj1, obj2) {

var value1 = document.getElementById(obj1).value;

var value2 = document.getElementById(obj2).value;

if (value1 == value2) {

alert('Values are the same');

return true;

} else {

return confirm('Two values are different.\nDo you want to continue?');

}

}

</script>

<apex:form>

<apex:inputtext id="txt1"/>

<apex:inputtext id="txt2"/>

<apex:commandButton value="Save" action="{!saveData}"

onclick="return validate('{!$component.txt1}', '{!$component.txt2}')"/>

</apex:form>

</apex:page> 

 

 

 

 

suneilchetlursuneilchetlur

Hi Prageeth ,

 

I had tried what you had suggested earlier too and it had indeed worked for input fields which were outside the pageblocktable.

But my scenario is where i have a inputfields inside a pageblocktable (which is inturn inside the pageblock which is indie a form)and somehow i am not able to extract the values of these fields which are inside the table.

 Any idea how to progress?

 

 

regards,

Suneil

Cool_DevloperCool_Devloper

Mr Suniel,

 

You have to loop through the table values and use the "index" to get the exact value in JS!!

 

Cool_D

suneilchetlursuneilchetlur

hello cool_d,

 

i am fairly new to javascripts,i tried doing something of what i understand from your suggestion,,..but came nowhere with this...could highly appreciate if you could give me some pointer on how to go about this.Heres the javascript in my VF code:

 

<script>

function confirmSave() {
alert('done');

var []qs1;
var mytab=document.getElementById('{!$Component.f.result.pbt}');
var str='abc';
for(var i=0;i<mytab.rows.length;i++) 
{
mytab.rows[i].ls1.innertext=str;
}
}
</script>

here f is the id of the form;result =id of pageblock and pbt =id of pageblocktable

ls1 is id of particular inputfield inside the table.

 

I want to extract the id of this input field and populate it with var str.

 

 

thanks

suneil

Cool_DevloperCool_Devloper

Mr Suniel, 

While you are looping over the table rows, you need to check for the ID which matches with the ID of the inputField you wanna refer to.

As soon as you get a match, you can do the assignment!!

Cool_D

prageethprageeth

Hello 

Actually the complexity of your task depends on the structure of your VF page. 

If your commandButtons/Button  is also inside the pagebolcktable you can access the components easily.

(See the following example. In this example I assume that your button is inside the table.) 

  If your button is outside the pageBlockTable you will have to do an iteration as mentioned by Cool_D(who is a guy I like).

But it would be more easier if your pageBlockTable does not grow dynamically. It means if your table has a fixed number of rows it is easy to accomplish your task.

So it would be easy for us to help you if you can post a sample + simple code of your page and controller here.

 

Controller: 

 

public class MyClass{

public void saveData() {

//do something

}

 

public List<String> getList() {

List<String> lst = new List<String>();

lst.add('');

lst.add('');

return lst;

}

}  

 

 

Page:

 

 

<apex:page controller="MyClass">

<script>

function validate(obj1, obj2) {

var value1 = document.getElementById(obj1).value;

var value2 = document.getElementById(obj2).value;

if (value1 == value2) {

alert('Values are the same');

return true;

} else {

return confirm('Two values are different.\nDo you want to continue?');

}

}

</script>

 

<apex:form id="myForm">

<apex:pageblock id="myPgBlock">

<apex:pageblocktable value="{!list}" var="v" id="myTable">

<apex:column>

<apex:inputtext id="txt1"/>

</apex:column>

<apex:column>

<apex:inputtext id="txt2"/>

</apex:column>

<apex:column>

<apex:commandButton value="Save" action="{!saveData}"

onclick="return validate('{!$component.txt1}', '{!$component.txt2}')"/>

</apex:column>

</apex:pageblocktable>

</apex:pageblock>

</apex:form>

</apex:page>  

 

 

Message Edited by prageeth on 11-16-2009 08:41 PM