[2 days left] What’s wrong with your cloud strategy? Learn why multicloud solutions matter with Nimble Storage.Register Now

x
?
Solved

jquery select all labels in form

Posted on 2010-11-11
4
Medium Priority
?
398 Views
Last Modified: 2012-08-14
hi there,

(i am using jquery-1.3.2.min.js and mvc)

I have several labels and textboxes in my page.  
50% of them have the word "Sdc" in the id  - i.e "SdcStartLabel" "SdcEndLabel" "SdcTextbox" etc etc

After the page has loaded, if a certain value is false - i want to disable all the labels and textboxes  that have "Sdc" in their id.

When i say disable - for the labels - i want to make the back ground grey - and put "N\A" and for the text inputs - to actually disable them.

Is this possible to do in one statement - rather than explicitly call every label and text box.

If so could someone show me how.

thanks



Once the
0
Comment
Question by:MrKevorkian
[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
  • 2
4 Comments
 
LVL 15

Expert Comment

by:Insoftservice
ID: 34110514
Hi

var trlist = $('tbl_registration').getElementsByTagName('label');
            var arrTr = $A(trlist).findAll(function (node){return node.id.match("^Sdc")});
            arrTr.each(function(node){
                  node.style.display = action ;
            });

u can change label and $('tbl_registration') to ur requirement
0
 
LVL 15

Expert Comment

by:Insoftservice
ID: 34110528
Hi,

where action = block or none .
which would do show and hide

u can even pass these parameter thru ur function so that only one function can be used to both label and ur textbox or checkbox and anything else
0
 
LVL 16

Accepted Solution

by:
Justin Mathews earned 1000 total points
ID: 34111748
Try this (replace variable cond with your condition):
<head>
<style>
.disable { 
background-color:#bca; 
border:1px solid green;
}
</style>
<script src="http://code.jquery.com/jquery-latest.min.js"></script>

<script>
var cond = false; //your conditon

$(document).ready(function () {
 if (!cond)
 {
	$('*[id^=Sdc]').each(function (){
		if ($(this).attr("tagname")=="LABEL")
			$(this).attr("className", "disable");
		if ($(this).attr("tagname")=="INPUT")
			$(this).attr("disabled", true);
	});
 }
});

</script>
</head>

Open in new window

0
 
LVL 1

Author Closing Comment

by:MrKevorkian
ID: 34111768
im going to go for this one, as it does the wildcarding which is what i hoping for
0

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to implement server side field validation and display customized error messages to the client.
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…

656 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