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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 16, 20262026-05-16T07:51:46+00:00 2026-05-16T07:51:46+00:00

I have the following code to hide/show elements depending on what value is selected

  • 0

I have the following code to hide/show elements depending on what value is selected in a dropdown list on a sharepoint form.

It works fine but I want to add some validation to it (required fields) depending on what is selected in the dropdown list “Level”.

Sharepoint has a default function called PreSaveItem() that I must call to not submit a page.

<script type="text/javascript">
//Items to hide when page first loads
$(document).ready(function ($) { 

$('nobr:contains("Vision")').closest('tr').show();
$('nobr:contains("Goal")').closest('tr').show();
$('nobr:contains("Performance")').closest('tr').hide();
$('nobr:contains("Start Date")').closest('tr').show();
$('nobr:contains("Target Date")').closest('tr').show();
});

</script>
<script type="text/javascript"> 

$(document).ready(function ($) { 
    $("select").bind("change", function(e){

    var thistag = e.target.title;
    var thisvalue =e.target.value;

if (thistag == "Level")
{

    if (thisvalue == "Vision") 
            {
$('nobr:contains("Vision")').closest('tr').hide();
$('nobr:contains("Goal")').closest('tr').hide();
$('nobr:contains("Performance")').closest('tr').hide();
$('nobr:contains("Start Date")').closest('tr').hide();
$('nobr:contains("Target Date")').closest('tr').hide();
};

    if (thisvalue == "Goal") 
            {
$('nobr:contains("Vision")').closest('tr').show();
$('nobr:contains("Priority")').closest('tr').show();
$('nobr:contains("Goal")').closest('tr').show();
$('nobr:contains("Performance")').closest('tr').hide();
$('nobr:contains("Start Date")').closest('tr').show();

$('nobr:contains("Target Date")').closest('tr').show();
};

    if (thisvalue == "Performance") 
            {
$('nobr:contains("Vision")').closest('tr').show();
$('nobr:contains("Goal")').closest('tr').show();
$('nobr:contains("Performance")').closest('tr').hide();
$('nobr:contains("Start Date")').closest('tr').hide();
$('nobr:contains("Target Date")').closest('tr').hide();
};

    if (thisvalue == "Actions") 
            {
$('nobr:contains("Vision")').closest('tr').show();
$('nobr:contains("Goal")').closest('tr').show();
$('nobr:contains("Performance")').closest('tr').hide();
$('nobr:contains("Start Date")').closest('tr').show();
$('nobr:contains("Target Date")').closest('tr').show();

};
};
});
   });

</script>


<script type="text/javascript">  

$(document).ready(function ($) { 
    $().SPServices.SPCascadeDropdowns({ 
            relationshipList: "Priority Tracking List",
            relationshipListParentColumn: "FoundationName",
            relationshipListChildColumn: "Title",
            parentColumn: "Vision",
            childColumn: "Goal"
        });

      });

</script>

My code to validate is(I put it inside the first script above):

//bind a change event to all controls to validate 
$("input[title=Target Date],input[title=Start Date],select[title=Vision],select[title=Goal]").change(function(){
    checkControls()
});

//the change event function - check the status of each control
function checkControls(){

//set a variable to count the number of valid controls
var controlsPassed = 0;

//set up a selector to pick .each() of the target controls
$("input[title=Target Date],input[title=Start Date],select[title=Vision],select[title=Goal]").each(function(){

//if the control value is not zero AND is not zero-length
if($(this).val() != 0 && $(this).val().length != 0) {

//add one to the counter
controlsPassed += 1
}

});

//call the showHide function and pass the true/false statement of 4 valid controls
return (controlsPassed == 4);
}
    function PreSaveItem() {
        return checkControls()
}

If the controls to validate are empty when I click Submit after page load nothing happens.
However, depending on what is selected in the dropdown list “Level” I want to check for different items to validate, how do I alter these scripts to achieve this?

  • 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-16T07:51:47+00:00Added an answer on May 16, 2026 at 7:51 am

    Going the minimal change route, you could change this:

    if($(this).val() != 0 && $(this).val().length != 0) {
    

    To this:

    var val = $(this).val();
    if($(this).is(':hidden') || (val != 0 && val.length != 0)) { 
    

    In this check if the control is :hidden it passes automatically, so effectively you’re not checking the hidden ones.

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

Sidebar

Ask A Question

Stats

  • Questions 507k
  • Answers 507k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The linker cannot find the library file. This could mean… May 16, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer The -v orders tar to print filenames as it extracts… May 16, 2026 at 4:09 pm
  • Editorial Team
    Editorial Team added an answer Both @"some string" (apparently not, read @BoltClock's second comment) and… May 16, 2026 at 4:09 pm

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Related Questions

I have the following code: var from = 0, step = 5; function showNext(list)
I have the following code working fine but the problem is that it always
I use the following code to hide and show a box on a bunch
I want to code a simple form layout in flex. Something like the following:
I have this jquery script which suppose to hide/show div element base on the
I have the following code (Yes I know it's quite long winded, but I
I have the following bit o' jquery: // Code for Side Navigation $(#sideNav ul
I have two elements src and dest src and dest are in different DOM-nodes,
In order to choose categories, I want to use dropdown lists. Each list contains
[Edit] See this post as to why I'm declaring form elements globally. I chose

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.