function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
justin_sfdcjustin_sfdc 

html input tag to direct to a field in custom object

Hi,

 

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!

Justin~sfdc

sfdcfoxsfdcfox

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.

justin_sfdcjustin_sfdc
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

Thanks,
Justin~sfdc
sfdcfoxsfdcfox
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.
justin_sfdcjustin_sfdc
Hi,

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.

--
Thanks,
justin~sfdc
sfdcfoxsfdcfox

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 ...>
    <script>
        function updateCountryValue(which) {
            updateViewCountry(which.id.match(/\d+$/)[0], which.value);
        }
    </script>
    <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}"/>
        </apex:repeat>
    </apex:form>
</apex:page>

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.