Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Code that works on Windows, Android and Iphone

Status
Not open for further replies.

rogerte

Programmer
Nov 9, 2001
164
0
0
GB
I have written a program for internal use using, mainly, PHP, but also has a lot of Javascript. It works absolutely fine using WIndows devices (including Windows phones), Android phones, and for the most part iPhones, but there are some items that don't work properly using the latter.

Generally they are where user interraction is required to "fire" the javascript.

1) On every page there is a back button. If the code is a straightforward href then no problem, but some pages can be called from different places fo I have used a javasript action:
Code:
<button onclick="window.history.back()">Back</button>
This works fine in everything but iphones.

2) On one page there is a set of checkboxes, and clicking any one of them fires a javascript code that counts number of items that are checked and if a certain number activates a button
Code:
                        for ($y = 0; $y < $itemcount; $y++) {
                            $chkval = $skills[$y];
                            $checked = '';
                            if ($chkval == "1") {
                                $checked = 'checked = "checked"  disabled="disabled"';
                            }
                            $id = " id = 'chk[".$memid.",".$y."]'";

                            echo '<td style="text-align: center;">';
                            echo "<input type='checkbox' class='checkbox checkbox-success' " . $checked .$id. "  onclick='chkcountfn($required,$y,\"$memid\") ' />";
                            echo'</td>';
JavaScript:
            function chkcountfn(required, col, memid) {
                let initid = "init" + memid;+
                let divid = "row" + memid;
                
                let dateid = "date" + memid;
                let savebtn = "save" + memid;
                let str = document.getElementById(divid).innerHTML;
                let origstr = document.getElementById(initid).innerHTML;
                let datestr = document.getElementById(dateid).innerHTML;
                let changestr = memid;
                let char = str[col];
                
                if (str[col] === "0") {
                    char = "1";
                } else {
                    char = "0";
                }
                charReplaced = replaceChar(str, char, col);
                
                document.getElementById(divid).innerHTML = charReplaced;
                //document.getElementById("changes").value = changestr;
                
                // to do: disable if origstr == charReplaced
                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;
            }
Using some, but not all, iPhones the checkbox clicks, but the javasript is ignored (ie the Save button is not activated). It seems that older iPhones are the main culprits, newer ones do seem to work most of the time.

I should emphasise that all iphones tested do have Javascript enabled, and in all other parts of the program Javascript acts as expected.

Many thanks for any help
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top