+ Start a Discussion
TheCustomCloudTheCustomCloud 

Retrieving a user inputted field before save

I have a button that when the user clicks it it is suppose to grab from the fields the user just filled in and say return them an alert message.  I am having trouble tho because the object is not saved so the values do no exist in the db yet.   

 

How do I retrieve values from the user's currently open page before they save those values? 

Message Edited by Redfin on 10-05-2009 02:28 PM
prageethprageeth

Are looking for a JavaScript solution?

Sometimes following code will be helpful.

 

<apex:page>

<script>

function showMessage(fieldId) {

alert(document.getElementById(fieldId).value);

}

</script>

<apex:form>

<apex:inputtext id="txt"/>

<apex:commandButton value="Click" onclick="showMessage('{!$component.txt}')"/>

</apex:form>  

</apex:page>

 

If your problem was not resolved yet, please supply an example and I can try to help you. 

TheCustomCloudTheCustomCloud

I have been playing around with your suggestion a lot and I just cannot get it working for what I need.

 

The script function on the page needs to pull the values that the user just entered (and has not saved) from the inputfields and then send these values through to the controller class.  The controller class then returns a URL in string format which is then used to open a new window.

 

Here is my code and it is not even popping the alert with this code. 

 

 <script>

 function openWin(fieldId){

alert(document.getElementById(fieldId).value);

</script> 

 

<apex:form>

  <apex:inputField value="{!pUnitsObject.Wt_Unit__c}" required="true" id="pUnits"/>

<apex:commandButton value="{!$Label.Get_Estimate}" onclick="openWin('{!$Component.pUnits}')" />

</apex:form>  

 

Message Edited by Redfin on 10-14-2009 11:18 AM
prageethprageeth

Hello Redfin;

 I copied your code and did some changes to be compatible with my account data as below. Changes are marked in green Color.

Unfortunately your code works fine in my account.

 

<apex:page standardController="Opportunity">

<script>

    function openWin(fieldId){

        alert(document.getElementById(fieldId).value);

    }

</script> 

 

    <apex:form >

        <apex:inputField value="{!opportunity.name}" required="true" id="pUnits"/>

        <apex:commandButton value="ClickMe" onclick="openWin('{!$Component.pUnits}')" />

    </apex:form>  

</apex:page> 

 

(I checked above code in FireFox, IE and Chrome. But no errors found. )

 

I'm still ready to help you...

TheCustomCloudTheCustomCloud

Thanks Pr(A+)geeth.

 

Going to try playing with this today using your suggested changes. 

TheCustomCloudTheCustomCloud

It just simply does not work for me.

 

I cannot even get the following to work..

 

alert('test' + '{!$Component.pUnits}');  

 

 

Do I have to take into account the form's ID?  for example one of the forms is  <apex:form id="pickupReqForm">  while the button is in a different form

 

prageethprageeth

Hi Redfin,

Of course you need to consider the id of the form if your CommandButton is in a different form.

In the same form you need not to do so. 

For an exampe,

<apex:page standardController="Opportunity">

<script>

function openWin(fieldId){

alert(document.getElementById(fieldId).value);

}

</script>

 

<apex:form id="pickupReqForm">

<apex:inputField value="{!opportunity.name}" required="true" id="pUnits"/>

<apex:commandButton value="ClickMe" onclick="openWin('{!$Component.pUnits}')" />

</apex:form>

 

<apex:form id="form2">

<apex:commandButton value="ClickMe" onclick="openWin('{!$Component.pickupReqForm.pUnits}')" />

</apex:form> 

</apex:page>