views:

44

answers:

3

I have a form which presents the user a list of checkboxes, some of which have the text label struckthrough some don't depending on initial conditions. This is functioning fine. During the form validation however, I would like to be able to detect which are struckthrough. I can figure out how to check if they're enabled, but whether the label is struckthrough is eluding me. Any ideas?

+1  A: 

You'll have to use the DOM methods (or jQuery) to look at the parent element of the text to see if its a <del> tag.

Can you provide some sample source so I might be able to elaborate with an example.

Darrell Brogdon
Here is the way I'm currently getting whether any of the checkboxes are checked and also specifically if one in particular is checked. var oSelect=document.getElementById("bldattempts"); for(i=0;i<oSelect.options.length;i++) { if (oSelect.options[i].selected) { selected.push(oSelect.options[i].value); count++; } } var hpuxsel=0; for (var a=0;a<selected.length;a++) { if(selected[a].indexOf("HPUX") != -1) { hpuxsel++; } }
Jim
Apologies, wrong code segment posted. please see: if (document.request_submit.Solaris.checked == true) { cnt++; }
Jim
So I have to actually agree with Bartek. Using jQuery would make this so much simpler. However, this code might be helpful:var inputs = document.getElementByTagName('input'), len=inputs.length;for (var x=0; x<len; x++){ var sibling = inputs[x].previousSibling; // Assuming 'sibling' is an element node if (sibling.nodeName == 'strike' || sibling.nodeName == 'del') { // Do something... }}
Darrell Brogdon
A: 

If the strikeout (your struckthrough) is assigned via a CSS class, you can simple detect the class (since you can already detect enabled/disabled). Else like Darrell mentioned, jQuery will be a great method.

o.k.w
+1  A: 

Doing this with jQuery just makes so much more sense then trying to mess around with plain Javascript. Here is what you need, basically:

striked = $("strike"); // As mentioned, you should use `del` .. strike is depreciated
$.each(striked, function(i, el) {
   alert($(el).html() + " is striked through. What do you want to do with it?");
});

Not sure what you want, but that would detect all elements with strike/del on your page. You can also change the search a bit, to restrict it to only within a certain form/div/whatever like so:

striked = $("strike", $("#myform_id"));

Hope that's what you were looking for.

Bartek
jquery roxmin15
Claudiu