我正在尝试为我的visualforce页面添加一些javascript,这也是一个force.com网站。
我已经尝试了几种不同的方法来获取一个字段是弹出的必需消息,但它不起作用。我粘贴了下面的代码,非常感谢任何帮助。
<apex:form >
<script>
function doValidation(){
var checkvalu = <apex:outputText value="{!customer}"/>;
if(checkValu.length >0){
saveNow();
}
else{
alert('Please fill out all fields!');
}
}
</script>
<apex:panelGrid styleClass="section">Please enter your contact information</apex:panelGrid>
<apex:panelGrid styleClass="survey">Name</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!customer}"/>
<apex:panelGrid styleClass="survey">Company</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!company}"/>
<apex:panelGrid styleClass="survey">Address</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!Address}"/>
<apex:panelGrid styleClass="survey">City/Town</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!city}"/>
<apex:panelGrid styleClass="survey">State/Province</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!state}"/>
<apex:panelGrid styleClass="survey">Zip/Postal Code</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!zip}"/>
<apex:panelGrid styleClass="survey">Country</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!country}"/>
<apex:panelGrid styleClass="survey">Email Address</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!email}"/>
<apex:panelGrid styleClass="survey">Phone Number</apex:panelGrid>
<apex:inputText styleClass="textarea" value="{!phone}"/>
答案 0 :(得分:0)
您可以使用特定组件的必需属性直接在Visualforce中创建一个字段
<apex:inputField value="{!Account.Name}" required="true"/>
要在VisualForce页面中使用Javascript创建一个字段,请
<apex:page StandardController="Account">
<script>
function setRequired() {
if (document
.getElementById('{!$Component.theForm.thePageBlock.thePageBlockSection.accPhone}').value == '')
alert("Phone number will not be blank");
}
</script>
<apex:form id="theForm">
<apex:pageBlock id="thePageBlock">
<apex:pageBlockButtons>
<apex:commandButton value="submit" action="{!save}"
onclick="setRequired();" />
</apex:pageBlockButtons>
<apex:pageBlockSection id="thePageBlockSection">
<apex:inputField id="accPhone" value="{!Account.Phone}" />
<apex:inputField value="{!Account.Name}" />
</apex:pageBlockSection>
</apex:pageBlock>
</apex:form>
</apex:page>
此致 纳文 软件工程师 http://www.autorabit.com