I'm new to developing visual force pages and forgive me if this is an easy question but I'm having problems getting the ID of an apex:inputfield and passing it to javascript. What I'm trying to do is
- create a link/button that will get the value (by passing ID) of a certain inputfield
- populate the other inputfields based on the value of #1
I have this code that calls the javascript
<apex:outputLink value="javascript:compute('{!$Component.Amount}', '{!$Component.lc1}', '{!$Component.lc2}', '{!$Component.lc3}', '{!$Component.lc4}', '{!$Component.lc5}', '{!$Component.lc6}')">Compute</apex:outputLink>
lc1, lc2, lc3...lc6 as you might guess are the ids of the variables im going to use.
Here comes the part where i get the problem of no id being passed, the javascript.
<script>
function compute(amount, lc1, lc2, lc3, lc4, lc5, lc6) {
alert(document.getElementById(amount));
/* Compute the loan charges depending on the loan amount here
document.getElementById(lc1).value = 6;
document.getElementById(lc2).value = 6;
document.getElementById(lc3).value = 5;
document.getElementById(lc4).value = 5;
document.getElementById(lc5).value = 5;
document.getElementById(lc6).value = 5;*/
}
</script>
The part alert(document.getElementById(amount)) should alert the id of amount inputfield right? What am I doing wrong here? Are there specific places where the javascript call or the script itself should be placed? Thanks for an answer in advance!
document.getElementById(amount)
you will get an object as an alert. Try alerting only thisalert(amount)
and this should give you the Id of the amount field – Sam Jul 5 '14 at 14:44