Developer forum

Forum » Templates » Dynamically setting value of a text box in Razor.

Dynamically setting value of a text box in Razor.

Yasharth Tahiliani
Reply

Hi,

I have a Forms For Editors Form and I output the form fields using the following Razor markup:

            <div class="form-input required textarea">
                <label for="enquiry">@GetString("Form.Field.Yourenquirycomments.Name")</label>
                <div class="field">
                    @GetString("Form.Field.Yourenquirycomments.Control")
                </div>
            </div>      

 

This works absolutely well. I am now looking to assign a value to the Form.Field.Yourenquirycomments.Text

How may I achieve this?

Thanks & Regards,

Yash.


Replies

 
Nicolai Høeg Pedersen
Reply

You can either add &Yourenquirycomments=value to the querystring, set the default value on the field in the forms administration or you have to make the control markup your self... ".Control" is build by using information that is also available in other template tags.

A complete hack could also be @GetString("Form.Field.Yourenquirycomments.Control").Replace("value=\"\"", "value=\"somevalue\"")

BR Nicolai

 
Yasharth Tahiliani
Reply

Hi Nicolai,

The thing is that I am sending the value as a query string parameter from another page on the website, so the field does not have a static default value as such. 

I think that the 2nd solution should work in this case.

Will let you know how it goes. Thanks :) 

Yash.

 
Nicolai Høeg Pedersen
Reply

If you have the value in the querystring already, you can just name the querystring parameter with the same name as the systemname of that field.

You have a field: <label>My field</label><input type="" id="" name="myFieldSystemName">

Then just add &myFieldSystemName=DefaultValue to the querystring, and you are set....

 

You must be logged in to post in the forum