0

I have the following javascript embedded in my view:

<script type="text/javascript">
    var Scripts = {

        showAddressForm: function (isNew) {
            if (isNew) {
                $('#newaddress-form').show();
            } else {
                $('#newaddress-form').hide();
            }
        },
    };
</script>

The function is called on the 'onchange' event of a dropdownlist. This works fine. However, when the page is initially loaded, the form is visible. I would like it to be hidden in this part of the code:

@if (Model.Addresses.Count > 0)
{
    //Call function to hide address form   

    //List dropdownlist items here...
}

What's the correct call to do this?

2 Answers 2

2

Render the form to be hidden with style="display: none;" or set it in your CSS:

#newaddress-form { display: none; }
Sign up to request clarification or add additional context in comments.

Comments

1

Why not just do...

@if (Model.Addresses.Count > 0)
{

    //Call function to hide address form   
    <script type="text/javascript">
        $(document).ready(function() {
            Scripts.showAddressForm(false);
        });
    </script>
    //List dropdownlist items here...
}

1 Comment

This is also a valid answer.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.