sniger
asked on
Regex search in javascript
I am finding the position of val by specifying html.search (new RegExp('-'+inp));
where inp = $val, but how to find the beginning of the string that is <label> ?
where inp = $val, but how to find the beginning of the string that is <label> ?
html = "
<label class= 'w'> <input name = '$name' value = '$key'
type = 'checkbox' checked ='yes' > $key-$val </label>";
<label class= 'w'> <input name = '$name' value = '$key'
type = 'checkbox' checked ='yes' > $key-$val </label>"
..
...
"
Try to look at the global HTML attributes supported by the label tag (http://www.w3schools.com/tags/tag_label.asp).
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I want to find the index of the <label> which is nearest to the string $val
lets say:
I have a string (which can be very long):
My inp would be: A.I. and I need the index of <label> which constains this string A.I.
lets say:
I have a string (which can be very long):
<label class="w"> <input name="innposn" id="inppos" class="w"> </label><label class="w"> <input name="Vend[]" value="376406" type="checkbox"> 376406-A.I. Editions Incorporated </label><label class="w"> <input name="Vend[]" value="584116" type="checkbox"> 584116-A.J. Incorporated
My inp would be: A.I. and I need the index of <label> which constains this string A.I.
I'm not sure you are looking for the ordinal number of the label which contains as value the string "A.I."; if so, try:
var myControl = document.getElementsByTagName("input");
var MyIndex=0;
for (var i=0; i<myControl.length; i++) {
if (myControlI[i].getAttribute("type") == "label" && myControlI[i].indexOf("A.I.")>=0) {
myIndex=i;
} else {
myControlI[i].checked=false;
}
}
ASKER
Sar1973, pelase understand, that everything is in the buffer (string), it is not DOM
Well, this was as close as I was able to come to what you're asking for; I have no clue how to get it to work in...whatever it is that you're trying to do...
ASKER
I made it work:
You pointed me into the right direction. thanks
<label class="w">\s+<input name="Vend\[]"+\svalue="\d{4,8}"\stype="checkbox">\s+.*-inp
You pointed me into the right direction. thanks
Cool, thanks. Glad I could help! :-)