Changing inputmode after page load only works once

Hi all,

I’m having trouble with my app on iOS where I need numerical input to be able to handle negative numbers. I found another forum post detailing the solution (Negative numbers on iOS keyboard), which I have implemented. This solution almost works…

My problem is that after I deploy the app, it works perfectly the first time. But when I refresh the page the original issue returns - iOS defaults to the numeric keyboard and I can’t enter negatives.

This the relevant code I am running in the page HTML header:

<script>
function fixios() {
var element = document.getElementById('negativeinput1').setAttribute("inputmode", "url");
var element = document.getElementById('negativeinput2').setAttribute("inputmode", "url");
var element = document.getElementById('negativeinput3').setAttribute("inputmode", "url");
var element = document.getElementById('negativeinput4').setAttribute("inputmode", "url");}
</script>
<body onload="fixios()">

Thanks in advance for your help!

In case it helps anyone else I seem to have solved the problem by wrapping the function with “$(document).ready(”

<script>  
$(document).ready(
    function fixios() {
	var element = document.getElementById('negativeinput1').setAttribute("inputmode", "url");
	var element = document.getElementById('negativeinput2').setAttribute("inputmode", "url");
	var element = document.getElementById('negativeinput3').setAttribute("inputmode", "url");
	var element = document.getElementById('negativeinput4').setAttribute("inputmode", "url");}    
);
</script>

I believe the issue was that after the first load the body onload=“fixios()” was cached, which was firing before the function itself was loaded