I have a page which is used to see if students have mastered certain elements in :a course.
It is quite simple, and works perfectly when using Windows or Linux PCs, Android devices and even old Windows phones (!), but get problems when using iPhones.
There are 2 problems depending on age of the iPhone.
Older iPhones don’t react to an onclick event:
for ($y = 0; $y < $itemcount; $y++) { $chkval = $skills[$y]; $checked = ''; if ($chkval == "1") { $checked = 'checked = "checked" disabled="disabled"'; } echo '<td style="text-align: center;">'; echo "<input type='checkbox' class='checkbox checkbox-success' " . $checked . " onclick='chkcountfn($required,$y,\"$memid\") ' />"; echo'</td>';
The called Javascript code is:
function chkcountfn(required, col, memid) {
let divid = "row" + memid;
let dateid = "date" + memid;
let savebtn = "save" + memid;
let skillstr = document.getElementById(divid).innerHTML;
let datestr = document.getElementById(dateid).innerHTML;
let changestr = memid;
let char = skillstr[col];
if (skillstr[col] === "0") {
char = "1";
} else {
char = "0";
}
charReplaced = replaceChar(skillstr, char, col);
alert(charReplaced); //<==========REMOVE===========================
document.getElementById(divid).innerHTML = charReplaced;
document.getElementById("changes").value = changestr; //Used to check if later user tries to leave page without saving
let btn = document.getElementById(savebtn);
if (btn.classList.contains('disabled')) {
// remove the class
btn.classList.remove('disabled');
}
let count = 0;
let ch = "1";
for (let i = 0; i < charReplaced.length; i++) {
if (charReplaced.charAt(i) == ch) {
count++;
}
}
if (count >= required) {
if (datestr.length === 0) {
alert("Required number of skills acheived");
var today = new Date();
var dd = today.getDate();
var mm = today.getMonth() + 1;
var yyyy = today.getFullYear();
if (dd < 10) {
dd = '0' + dd;
}
if (mm < 10) {
mm = '0' + mm;
}
today = dd + '/' + mm + '/' + yyyy;
document.getElementById(dateid).innerHTML = today;
}
}
}
function replaceChar(origString, replaceChar, index) {
let firstPart = origString.substr(0, index);
let lastPart = origString.substr(index + 1);
let newString = firstPart + replaceChar + lastPart;
return newString;
}
In the case of older iPhones it would appear this Javascript code is not executed.
Secondly newer iPhones do use the above code, but when data is written back to the database using the Save button it gets corrupted:
The Save button code:
echo '<td style="text-align: center;"><a href = "javascript:savefn(' . $memid . ')" class = "btn btn-warning disabled" id="' . $saveid . '" ><span class = "fa fa-save"></span> Save</a></td>'
which calls the following Javascript code:
function savefn(memid) { let divid = "row" + memid; let dateid = "date" + memid; let savebtn = "save" + memid; let classstr = <?php echo $classid; ?>; let badgestr = <?php echo $badgeid; ?>; let skillstr = document.getElementById(divid).innerHTML; let datestr = document.getElementById(dateid).innerHTML; //window.location.href = 'updatememberbadge.php?varr=' + passvar; window.location = "updatememberbadge.php?varr=" + classstr + "!" + badgestr + "!" + memid + "!" + skillstr + "!" + datestr; }
WHenever this executed by an iPhone the word “href” is inserted somewhere in the skillstr string, for example if the skillstr was “11111011110” any 4 of those characters would be replaced by href e.g. “111href1110”
Unfortunately, I do.n’t have an iPhone so am having difficulty understanding what the problem is, and testing it. W. Thanksould be grateful for any ideas