Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Need JQuery Function to check if field is Null in ASP.NET (SharePoint)

Posted on 2012-03-30
8
Medium Priority
?
437 Views
Last Modified: 2012-04-05
I have a form that I am building in SharePoint Designer 2007 that has several fields that are required depending on the value of a specific field, so I need to create my own required field indicator. For example

when field is empty:
label     Field1 *

when field has a value:
label     Field1
 
I would like to have an '*' next to an empty required field and have the '*' be hidden when the field(s) has a value.

Another problem I am having is that when I use the <SharePoint:FormField ..../> tag with a <P>*</P>.   The '*' is put on another line instead of next to my field.
0
Comment
Question by:macarrillo1
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 3
8 Comments
 
LVL 51

Expert Comment

by:Ted Bouskill
ID: 37791294
There are client-side validation controls available in ASP.NET that will do what you require.  They generate the client side JavaScript & also validate the forms server-side to do things like prevent SQL injection attacks.  Why are you not using them?
0
 
LVL 9

Author Comment

by:macarrillo1
ID: 37791343
I need to build a form that has required fields that are dependent on the value of a field as follows:

Field 1 (Required)*
Field 2 (not Required)

Field 3 (If Field 1 = A then Required and visible else Not required and Hidden)*
Field 4 (if Field 1 = B Then Required and visible else Not required and Hidden)*

I want the '*' to appear next to required fields and disappear when the field has data.
so far I have a function that is not working ( I know I am using the click event instead of the change event to accelerate testing) as follows:

$(document).ready(function()    {
     $("input[id*=ff5]").click(function()    {
         $("div#ff5".hide();
         });
});

This is within a <Script type="text/javascript"> tag and of course include the Script with the jquery-1.7.2.js src.

I used the input tag because I can't directly reference SharePoint:FormField.

I do have a question; does it matter if I use the single quote or double quotes?
0
 
LVL 9

Author Comment

by:macarrillo1
ID: 37791377
Ah!  Turned out I misspelled the jquery src.  So now this works.
Now I need to make this an on change event and check if it is null.
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 51

Assisted Solution

by:Ted Bouskill
Ted Bouskill earned 2000 total points
ID: 37791387
0
 
LVL 9

Author Comment

by:macarrillo1
ID: 37791431
Ok,

How do I adapt this function to check if the field is Null?

$(document).ready(function()    {
     $("input[id*=ff5]").Change(function()    {
         $("div#ff5".hide();
         });
     $("input[id*=ff5]").Change(function()    {
         $("div#ff5".show();
         });

});
0
 
LVL 51

Accepted Solution

by:
Ted Bouskill earned 2000 total points
ID: 37791614
There is no such thing as Null on the client.  You have to check for an empty string or a string length of 0
0
 
LVL 9

Assisted Solution

by:macarrillo1
macarrillo1 earned 0 total points
ID: 37791678
I was able to get this to work with your suggestions and some additional informaiton from StackOverflow.

$(document).ready(function()    {
     $("input[id*=ff5]").Change(function()    {
          var f=$.trim(S("input[id*=ff5]").val()).length;
          if(f==0) {
              $("div#ff5").show();
          }
          else   {
              $("div#ff5").hide();
         }
         });
});

Thanks Again!

I will most likely be opening another question on Monday to adapt this function to validate multiple
fields instead of just a single specific field.
0
 
LVL 9

Author Closing Comment

by:macarrillo1
ID: 37810110
I select my comment as part of the solution as it was a summation of all the suggestions needed to complete the solution.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question