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

  • Home
  • SEARCH
  • 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 3361348
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 18, 20262026-05-18T03:08:30+00:00 2026-05-18T03:08:30+00:00

I have a website written in ASP.NET MVC and I have a parameter set

  • 0

I have a website written in ASP.NET MVC and I have a parameter set to the page in question that specifies what the preceding page is. The reasoning for this is so when a user clicks an image from a particular page, the loaded page will automatically check the appropriate check box using javascript (jQuery particularly).

Here is the code that gets and sets the parameter:

<script type="text/C#" runat="server">
    protected string Referrer = string.Empty;
    protected override void OnLoad(EventArgs e)
    {
        try
        {
            Referrer = Request.UrlReferrer.Segments[2].ToLower();
        }
        catch (System.Exception)
        {

            Referrer = string.Empty;
        }
        base.OnLoad(e);
    }
</script>

Next, here is the collection of check-boxes:

<div id="interestSelect1" class="interestPad">
        <%= Html.CheckBoxFor(model => model.Interests[0])%>
        <label for="Interests_0_">Insulation</label>
        <%= Html.CheckBoxFor(model => model.Interests[1])%>
        <label for="Interests_1_">Windows</label>
        <%= Html.CheckBoxFor(model => model.Interests[2])%>
        <label for="Interests_2_">Siding</label>
        <%= Html.CheckBoxFor(model => model.Interests[3])%>
        <label for="Interests_3_">Roofing</label>
    </div>
    <div class="clear">
    </div>
    <div id="interestSelect2" class="interestPad">
        <%= Html.CheckBoxFor(model => model.Interests[4])%>
        <label for="Interests_4_">Gutters/Protection</label>
        <%= Html.CheckBoxFor(model => model.Interests[5])%>
        <label for="Interests_5_">Patio Doors</label>
    </div>

When rendered in the browser, here is what each of the check-boxes look like:

<input id="Interests_0_" name="Interests[0]" type="checkbox" value="true" />
<input name="Interests[0]" type="hidden" value="false" />
<label for="Interests_0_">Insulation</label>

Here is the javascript that I am using, that is not working:

<script type="text/javascript">
    var ref = '<%= Referrer %>';
    $(document).ready(function () {
        switch (ref) {
            case "insulation":
                $('Interests_0_').attr('checked', 'checked');
                break;
            case "windows":
                $('Interests_1_').attr('checked', 'checked');
                break;
            case "siding":
                $('Interests_2_').attr('checked', 'checked');
                break;
            case "roofing":
                $('Interests_3_').attr('checked', 'checked');
                break;
            case "gutters":
                $('Interests_4_').attr('checked', 'checked');
                break;
            case "patiodoors":
                $('Interests_5_').attr('checked', 'checked');
                break;
            default:
                // do nothing, not valid ref
        }
    });
</script>

I am obviously doing something completely wrong, can anyone point me in the right direction?

Thanks!

EDIT: Looks like another JS file that was on a MasterPage that was called before my JS block was causing the boxes to not be checked. The main problem was forgetting the # identifier.

  • 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-05-18T03:08:31+00:00Added an answer on May 18, 2026 at 3:08 am

    #id selectors need a # prefix, like this:

    $('#Interests_0_').attr('checked', 'checked');
    

    Without the #, it’s an element selector, looking for a <Interests_0_> element.

    You can slim it down overall with an object though, like this:

    var ref = '<%= Referrer %>';
    var map = {"insultation":"#Interests_0_",
               "windows":"#Interests_1_",
               "siding":"#Interests_2_",
               "roofing":"#Interests_3_",
               "gutters":"#Interests_4_",
               "patiodoors":"#Interests_5_"};
    $(function () {
       var id = map[ref];
       if(id) $(id).attr('checked', true);
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have written an ASP.NET MVC application that allows the user to specify their
I have a website (ASP.NET) and some winforms(.Net 2.0) for a project (written in
I'm building an ASP.Net MVC website. Rather than have everything in one project, I've
I have decided to use ASP.NET MVC for a website project and want to
I have an application to be written in ASP.Net 3.5 that needs to manage
I've written my website using ASP.NET MVC and SQL Server (used a SQL Server
I have a website written in Classic ASP and ASP.NET, after a few redirects
I currently have a website written in classic asp that runs multiple queries against
I have recently inherited a website written in Classic ASP, and am currently trying
I have a website cgi-bin program that is written in c++. Unfortunately the website

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.