Incorporating both AJAX and PHP technologies, I have placed specific text data within a span element located at the bottom of my webpage. Now, my objective is to search this text for a given string. The page consists of multiple checkboxes, with each checkbox corresponding to a particular value that needs to be searched.
Objective: Employing a loop mechanism, iterate through all the checkboxes present on the page. Search the entire page for each checkbox's value (ideally within the text contained in the span informed by AJAX). If a match is found, modify the CSS style color of that particular checkbox.
The current state of my code involves a form containing checkboxes where they are named "comment" and possess unique IDs:
<input type="checkbox" name="comment" id="hjl1" value="the comment."
onclick="createOrder()"><label for="hjl1" onclick="createOrder()"
title="comment"> textual representation for this checkbox </label>
Upon activation, using JavaScript, I traverse through every checkbox within the form.
var comment=document.forms[0].comment;
var str="";
var ii;
for (ii=0;ii<comment.length;ii++)
{str=comment[ii].value;}
My next step involves integrating window.find into that loop to verify if that particular value exists on the page.
if (window.find) {
var found = window.find (str);
if (!found) {
document.getElementById("?????").style["color"] = "red";
}
}
The concept revolves around checking for the presence of "the comment." value on the page when its corresponding checkbox is activated. Upon discovery, the checkbox label will display the CSS style color as red.
I aim to consolidate these concepts, yet numerous obstacles hinder progress. How can I access elements by their IDs within this loop? Is it feasible for window.find to scan the text generated by PHP in my span?
Would it prove more efficient to abstain from utilizing window.find entirely?
var source = document.getElementsByTagName('html')[0].innerHTML;
var found = source.search("searchString");
This process bewilders me as I am relatively inexperienced. Your patience and time spent reading thus far are sincerely appreciated.