Reputation: 1019
I'm adding javascript method in sharepoint where I need to get elements by title and Id and Names are changeing. I'm not sure of the syntax for writing such a method and I can't find good examples of doing so. Please help. My code looks like this for now.
function ValidateComments()
{
var val1 = elements[index].title("inspection");
var val2 = elements[index].title("Start date");
var val3 = elements[index].title("End date");
var val4 = elements[index].title("Comments");
if (val1 === true){
if ((val2 !== "" && val3 !== "") || val4 !="")
}
alert("Valid");
}
else {
alert("NOT Valid");
}
Upvotes: 0
Views: 4948
Reputation: 874
Try something like below code :
var val1 = document.querySelector('[title="inspection"]').value;
Note: It returns the first Element within the document that matches the specified selector, or group of selectors, or null if no matches are found.
Upvotes: 2