javascript - document.getElementById().value does not work in form's hidden field asp.net web pages -
i created simple website using asp.net web pages (using razor markup). have form 2 hidden fields: latitude
, longitude
. in js script use html5 geolocation api user's location expressed in degrees (latitude , longitude) , try assign these values 2 hidden fields in form before sending them out server.
the problem use getelementbyid().value
method assign these value , not seem work! can print out values in same place in script using simple alert()
message i'm pretty sure it's getelementbyid().value
doesn't work.
here's code form:
<form id="locationform" method="post" action="" onsubmit="return getlocation()"> search cinema showings in area<br /> <input type="hidden" name="latitude" id="latitude" value="" /> <input type="hidden" name="longitude" id="longitude" value=""/> <input type="submit" value="submit" class="submit"/> </form>
and here's code script:
<script> function getlocation() { if (navigator.geolocation) { navigator.geolocation.getcurrentposition(showposition); } else { alert("geolocation not supported browser."); } } function showposition(position) { var lat = position.coords.latitude; alert("lat is: " + lat); document.getelementbyid('latitude').value = position.coords.latitude; document.getelementbyid("longitude").value = position.coords.longitude; }
i apologize english ... native language portuguese / brazil.
i have same problem. had check codes in many browsers , windows versions.
document . getelementbyid (hiddenformvariable) . value = 'string' not run in ...
- ie 11 windows 7:does not run
- mozila windows 7: does not run
- chrome 37.0.2062.124 vista business: does not run
- chrome 38.0.2125 windows 7: does not run
- chrome 38.0.2125 windows xp: does not run
- ie 9 windows vista business: run
- ie 7 windows xp: run
but ..
in windows explorer 11, if change in [tools] > [compatibility view settings]
, include site @ list run ok in windows 7 ie 11. not bug, changed ie. chrome not accept change - hidden input in of windows or old version have checked.
i solved way
where had <input type="hidden">
i changed to
<div style="visibility:hidden"> <input type="text"> </div>
text inputs can changed javascript , inside div
not need showed on screen.
Comments
Post a Comment