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 6321229
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T16:06:50+00:00 2026-05-24T16:06:50+00:00

I have got [hide] and [unhide] input buttons , the hide button shows some

  • 0

I have got [hide] and [unhide] input buttons , the hide button shows some text boxes while the hidden button hide some text boxes, What I want to do is to enable validation only for those boxes which are visible and disable validation for the boxes which are not visible to client. Currently I am validating on all the boxes, the post action also validates the text boxes which are hidden through jquery , below is the code :

View

<script type="text/javascript">

$(document).ready(function () {
    var $startdates = $('#startDates');
    var $endDates = $('#endDates');
    var $showEvents = $('#showEvents');
    $startdates.hide();
    $endDates.hide();
    $showEvents.hide();

    $('#all').click(function () {
        $startdates.show();
        $endDates.show();
        $('#showEvents').show();
        $('#eventdids').hide();
        $(this).hide();
        return false;

    });

    $('#showEvents').click(function () {
        $startdates.hide();
        $endDates.hide();

        $('#eventdids').show();
        $('#all').show();
        $(this).hide();
        return false;

    });
});
 </script>
<tr id="startDates">
        <td>
        <div class="editor-label">
            <%: Html.LabelFor(model => model.StartDate) %>
        </div>
        </td>
        <td>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.StartDate) %>
            <%: Html.ValidationMessageFor(model => model.StartDate) %>
        </div>
        </td>
        </tr>

        <tr id="endDates">
        <td>
        <div class="editor-label">
            <%: Html.LabelFor(model => model.EndDate) %>
        </div>
        </td>
        <td>
        <div class="editor-field">
            <%: Html.TextBoxFor(model => model.EndDate) %>
            <%: Html.ValidationMessageFor(model => model.EndDate) %>
        </div>
        </td>
        </tr>


        <tr id="eventdids">
        <td>
        <label>Events</label>
        </td>
        <td>
         <% foreach (var item in (SelectList)ViewData["events"]) { %>
                 <input type="checkbox" name="Name" value="<%=item.Value %>" />
                  <label for="<%=item.Value%>"><%=item.Text%></label>
                  <br />

        <% } %> 

        </td>
        <td><input type="button" name="Select" id="all" style="width:auto" value="Hide" /></td>


        </tr>

        </table>
      <input type="button" name="show" id="showEvents" style="width:auto" value="Show" />

        <p>
            <input type="submit" value="Create" />
        </p>

Controller:

 [HttpPost]
    public ActionResult Create(FormCollection collection, int[] Name)
    {

        IVoucherRepository voucherResp = new VoucherRepository();
            string empty = "";
            if (Name != null)
            {
                for (int i = 0; i < Name.Length; i++)
                {
                    empty += Convert.ToString(Name[i]) + ",";
                }

            }
            else
            {
                ModelState.AddModelError("Venue", "Required");

            }
            if (Convert.ToBoolean(collection["pound"].ToLower().StartsWith("false")) && Convert.ToBoolean(collection["percentage"].ToLower().StartsWith("false")))
            {
                ModelState.AddModelError("","Please Select £ or % for discount");
            }
            if (collection["UsageQtyAvailable"] == null) { ModelState.AddModelError("UsageQtyLeft", "Required "); }

            Voucher voucher = new Voucher();
            if (TryUpdateModel(voucher) && ModelState.IsValid)
            {
                voucher.Status = true;
                voucher.DateAdded = DateTime.Now;
                voucher.DateModified = DateTime.Now;
                if(Convert.ToBoolean(collection["pound"].ToLower().StartsWith("true")))
                {
                voucher.DiscountType = 1;
                }
                else if (Convert.ToBoolean(collection["percentage"].ToLower().StartsWith("true")))
                {
                    voucher.DiscountType = 2;
                }
                voucher.VoucherType = 1; //Discount Code
                voucher.UsageQtyLeft = Convert.ToInt32(collection["UsageQtyAvailable"]);
                string removeComma = empty.Remove(empty.Length - 1,1);
                voucher.EventIDs = removeComma;
                voucherResp.Add(voucher);
                voucherResp.Save();
                return RedirectToAction("Index");
            }

            ITrackdayRepository trackdayResp = new TrackdayRepository();
            IQueryable<Object> getAllEvents = trackdayResp.GetEventsSelectlist();

            ViewData["events"] = new SelectList(getAllEvents.ToList(), "EventID", "Name");
            return View();

    }
  • 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-24T16:06:50+00:00Added an answer on May 24, 2026 at 4:06 pm

    You could check via jquery if the text boxes are hidden and remove them before submitting the form and subsequently only validate submitted form elements.

    ...
    <input type="submit" value="Create" id="create" />
    ...
    
    $("#create").click(function() { 
            $('#eventdids:hidden').remove();
            $('#all:hidden').remove();
        $("#formID").submit(); 
    });
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've got two input boxes in a div, I want to hide that div
I got a page of Products. Some products have multiple images (colors). I want
I have some nested tables that I want to hide/show upon a click on
Have got an NSString *str = @12345.6789 and want to find out if there
I have got some code to load an assembly and get all types, which
I have got many dropdowns in my site and i want to make a
I have a cursor, and it got, lets say, 40 rows, I want to
I have a simple form. Its got one field and a submit button. I
I've got a simple dropdown menu that I want to hide whenever you click
I've got several Portlets with some links in them, all I want is to

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.