View Single Post
Old 10-03-2010, 10:08 PM   PM User | #1
bwalls
New to the CF scene

 
Join Date: Oct 2010
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
bwalls is an unknown quantity at this point
Regular Expression headache

I have a function that changes the label on a set of labels with similar "for" fields. Somehow, the matching is only matching every other label. I suspect I must be missing something obvious.

The goal is to change the text of a set of radio buttons to either "top" and "bottom" or "left" and "right" depending on orientation.

Code:
function ChangeLabels(orientation) {
	var lefttop = 	"Left";
	var bottomright = 	"Right";
    var lbls = document.getElementsByTagName("label");
    var lefttopregex = new RegExp ("Field6_[0-9]+", "gi");
    var bottomrightregex = new RegExp ("Field20_","gi");
    
    
    if (orientation == "Vertical") {
    	lefttop = "Top";
    	bottomright = "Bottom";
    }

  var forvalue = "";
  for (var i=0,k=lbls.length; i<k; i++) {
     	forvalue = lbls[i].htmlFor;
    
   	if (lefttopregex.test(forvalue)) {
      		lbls[i].innerHTML = lefttop;
    }
   	if (bottomrightregex.test(forvalue)) {
      		lbls[i].innerHTML = bottomright;
    }
     
  }	
	
}
And here is the HTML of the labels.

Code:
<li id="fo1li6" class="     ">
<label class="desc" id="title6" for="Field6_0">
Left/Top
<span id="req_6" class="req">*</span>
</label>
<div>
<input id="radioDefault_6" name="Field6" type="hidden" value="" />
<span>
<input id="Field6_0" name="Field6" type="radio" class="field radio" value="Dogs" tabindex="20" onchange="handleInput(this);"  checked="checked" />
<label class="choice" for="Field6_0" >
Dogs</label>
</span>
<span>
<input id="Field6_1" name="Field6" type="radio" class="field radio" value="Pineapple" tabindex="21" onchange="handleInput(this);" />
<label class="choice" for="Field6_1" >
Pineapple</label>
</span>
<span>
<input id="Field6_2" name="Field6" type="radio" class="field radio" value="Leaves" tabindex="22" onchange="handleInput(this);" />
<label class="choice" for="Field6_2" >
Leaves</label>
</span>
<span>
<input id="Field6_3" name="Field6" type="radio" class="field radio" value="Cat" tabindex="23" onchange="handleInput(this);" />
<label class="choice" for="Field6_3" >
Cat</label>
</span>
<span>
<input id="Field6_4" name="Field6" type="radio" class="field radio" value="Star" tabindex="24" onchange="handleInput(this);" />
<label class="choice" for="Field6_4" >
Star</label>
</span>
<span>
<input id="Field6_5" name="Field6" type="radio" class="field radio" value="Bamboo &amp; Sun" tabindex="25" onchange="handleInput(this);" />
<label class="choice" for="Field6_5" >
Bamboo & Sun</label>
</span>
<span>
<input id="Field6_6" name="Field6" type="radio" class="field radio" value="Bamboo" tabindex="26" onchange="handleInput(this);" />
<label class="choice" for="Field6_6" >
Bamboo</label>
</span>
<span>
<input id="Field6_7" name="Field6" type="radio" class="field radio" value="Sun &amp; Moon" tabindex="27" onchange="handleInput(this);" />
<label class="choice" for="Field6_7" >
Sun & Moon</label>
</span>
<span>
<input id="Field6_8" name="Field6" type="radio" class="field radio" value="Fleur de lis" tabindex="28" onchange="handleInput(this);" />
<label class="choice" for="Field6_8" >
Fleur de lis</label>
</span>
<span>
<input id="Field6_9" name="Field6" type="radio" class="field radio" value="Dragonflies" tabindex="29" onchange="handleInput(this);" />
<label class="choice" for="Field6_9" >
Dragonflies</label>
</span>
<span>
<input id="Field6_10" name="Field6" type="radio" class="field radio" value="No Design" tabindex="30" onchange="handleInput(this);" />
<label class="choice" for="Field6_10" >
No Design</label>
</span>
</div>
</li>
bwalls is offline   Reply With Quote