You need to sign in to do that
Don't have an account?

hidden field value at onload event
hi
I am trying to set hidden field value at onload event,but i am not able to do this.
here is my code:
<apex:page controller="TestForProfile" action="{!hello}">
<apex:outputLink value="https://www.salesforce.com" id="theLink" disabled="{!linkDisabled}">www.salesforce.com</apex:outputLink>
<apex:outputText value="{!$Profile.Name}"></apex:outputText>
<apex:outputText value="{!myObject.hiddenField}"></apex:outputText>
<apex:form id="form" >
<apex:inputhidden id="otherName" value="{!myObject.hiddenField}" />
<apex:commandButton action="{!hello}" onclick="changeValue()"></apex:commandButton>
<script>
var otherName = document.getElementById("{!$Component.otherName}");
</script>
</apex:form>
<script>
window.onload = new function() {
otherName.value = "{!$Profile.Name}";
alert("hello" + otherName.value);
};
function changeValue() {
alert(otherName.value);
otherName.value = "{!$Profile.Name}";
return true;
}
</script>
<apex:outputLink value="https://www.salesforce.com" id="theLink" disabled="{!linkDisabled}">www.salesforce.com</apex:outputLink>
<apex:outputText value="{!$Profile.Name}"></apex:outputText>
<apex:outputText value="{!myObject.hiddenField}"></apex:outputText>
<apex:form id="form" >
<apex:inputhidden id="otherName" value="{!myObject.hiddenField}" />
<apex:commandButton action="{!hello}" onclick="changeValue()"></apex:commandButton>
<script>
var otherName = document.getElementById("{!$Component.otherName}");
</script>
</apex:form>
<script>
window.onload = new function() {
otherName.value = "{!$Profile.Name}";
alert("hello" + otherName.value);
};
function changeValue() {
alert(otherName.value);
otherName.value = "{!$Profile.Name}";
return true;
}
</script>
</apex:page>
========================================
controller
=========================================
public class TestForProfile
{
{
public PageReference hello() {
System.debug('*****************'+getMyObject().hiddenField);
if(getMyObject().hiddenField=='System Administrator')
{
linkDisabled = true;
}
return null;
}
System.debug('*****************'+getMyObject().hiddenField);
if(getMyObject().hiddenField=='System Administrator')
{
linkDisabled = true;
}
return null;
}
Boolean linkDisabled = false;
public Boolean getLinkDisabled () {
return linkDisabled ;
}
public class MyObject {
private String hiddenField = 'Lorem ipsum dolor';
public String getHiddenField() { return hiddenField; }
public void setHiddenField(String data) { hiddenField = data; }
}
public void setHiddenField(String data) { hiddenField = data; }
}
private myObject my_object;
public MyObject getMyObject() {
if (my_object == null) { my_object = new MyObject(); }
return my_object;
}
public String handleSubmit() {
return null;
}
if (my_object == null) { my_object = new MyObject(); }
return my_object;
}
public String handleSubmit() {
return null;
}
}
At onclick event the hidden field value has been set. but I want to set hidden field value at onload event.
Inside
window.onload = new function() {
otherName.value = "{!$Profile.Name}";
alert("hello" + otherName.value);
otherName.value = "{!$Profile.Name}";
alert("hello" + otherName.value);
alert gives the changed value but in <apex:outputText value="{!myObject.hiddenField}"></apex:outputText>
It gives previous value. please give me a appropriate answer.
Thanks & Regards
Brijesh Kumar Baser
Hi,
I also have a similar req, do you have any solution for it
thanks,
Bob