Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7961097
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 4, 20262026-06-04T04:56:19+00:00 2026-06-04T04:56:19+00:00

As the title suggests, I am trying to essentially copy values from one textbox

  • 0

As the title suggests, I am trying to essentially copy values from one textbox to another after a checkbox is clicked. I know how to do this via javascript, the only problem is it needs to be done server-side with razor. I am trying to accomplish this with the code below however, it has been giving me the infamous “object reference not set to an instance of an object.” error. But I’m not exactly sure what it’s refering to, any help would be appreciated.

<div class="editor-field">
    @Html.CheckBoxFor(model => model.SameAddress, new { id = "chkAddress" })

    @{bool isChecked = false; 
        if (Boolean.TryParse(Request.Form.GetValues("chkAddress")[1], out isChecked) == true)
        {

        }
    }
</div> 
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-04T04:56:20+00:00Added an answer on June 4, 2026 at 4:56 am

    Razor is not going to help you in this. There are 2 ways to do this.

    1) Use javascript : Listen for the checkbox change event and if it is checked, read the content of first text box and paste it in second. This is the preferred i would go for.

    Some thing like this

    $(function(){
        $("#chkCopy").change(function(){
            $("#address2").val("");
           if(this.checked)
           {
                $("#address2").val($("#address1").val())
    
                //Lets read city and paste it in the second place as well.
                $("#city2").val($("#city1").val())
           }                
        });
    });​
    

    Assuming you want to copy from textbox with id address1 to textbox with id address2 when checkbox with id chkCopy is clicked

    working sample : http://jsfiddle.net/9fM89/4/

    2) Using a formpost : Let the user clicks on “Copy” button and it does a form submit to your action method where you read the values of those form elements and set it on those properties meant for the second check box and return that to the view.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

As the title suggests is it possible to execute another java app from within
So as the title suggests, I'm trying to get and gunzip a string from
As the title suggests, is it correct or valid to import/export static data from
As the title suggests, I'm trying to get the caption of the associated label
As the title suggests I am trying to add an event listener to a
As the title suggests I'm simply trying to get a named window to come
I know this is a bad title for my question but what i am
As the title suggests I've been trying to trigger a onmousedown even and then
As the Title suggests, i am trying to find how to insert image in
As the title suggests, I am trying to nest - or create an array

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.