+ Start a Discussion

html input tag to direct to a field in custom object



I am using an html input tag. How do i direct it to a particular field in custom object?


Example: if I say input tag to be name and I want to store it in a field called FirstName which is in custom Object: "info" then how would I do it?


<apex:outputLabel value="name" for= "name"/>

<input type="text" id="fName" value = "{!sth that the user will input}" />


Thanks Much!



You need to use either apex:inputField, or to override the type of the field, you can use apex:inputText, apex:inputCheckbox, apex:selectList, etc. Check out the Visualforce developer's guide or the Component reference.

Hi sfdcfox,
Thanks for the response. Actually i'm using al these under an apex: repeat function. The given input functionality gets repeated depending upon number of users so, everytime it is repeated, i wanna give it a separate id. And as we cannot do this in

inputfield="" id="country{!x}" value="{!address.country__c}">

this is why i had to use html input tag jnstead of vf component and am unaware of how to direct it to that particular field in the object

You can't use merge fields in an ID attribute, as you've discovered. Instead, use just a fixed ID; the repeat tag will automatically add a number to each row automatically.

You are correct as well, "the repeat tag will each time add a number" but
it only does it in this way: Lets say if the id= country and repeat block
repeats the same function 3 times then we get the id;s in this way=>
repeatblock0:country, repeatblock1:country, repeatblock2:country.

But I wanted the id as Country1, country2, country3. and I am able to
achieve this functionality using , and input html tag.


If you don't bind to an apex:* attribute, you will have to accept the consequences. Mostly, this means that you'll need action functions to update the view state using JavaScript before any other action is executed. I believe that the most profound effect is that this may reduce the page's responsiveness. I'm hesitant to actually write a demonstration for this, because the exact structure that one might need depends on the mixture of HTML and Visualforce, etc. Generically, though, it might look like this:


public class mycontroller {
    // addresses
public address__c[] addresses { get; set; } // other code here
// action function public void updateCountry(Integer which, String value) { addresses[which].country__c = value; } }
<apex:page ...>
        function updateCountryValue(which) {
            updateViewCountry(which.id.match(/\d+$/)[0], which.value);
    <apex:form id="form">
        <apex:actionFunction action="{!updateCountry}" reRender="form" name="updateViewCountry"/>
        <apex:variable var="counter" value="{!0}"/>
        <apex:repeat value="{!addresses}" var="address">
            <input type="text" id="country{!counter}" value="{!address.country__c}" onchange="updateCountryValue(this)" />
            <apex:variable var="counter" value="{!counter+1}"/>

This code is simplified, but illustrates the potential annoyances you'll have to go through. You'll also have to address the loss of focus, adding/removing rows (possibly), and so on. Each extra feature will become increasingly costly to implement compared to native Visualforce.


Of course, the alternative would be to have the entire form be hidden and the remainder of the page rendered by JavaScript. This would give you more control over the focus of the page, but would make the page even more complex to manage.