need your help.
I am not sure what I am doing, and I also mix jQuery and JS together to an extend which is simply not making any sense, but I don't know what to do and how to approach this issue.
I want the value
of the #third-input
in my form
to be updated with the coordinates once form
was submitted
.
<form class="flex-form" action="MAILTO:someone@example.com" method="post" enctype="text/plain">
<input id="first-input" type="text" placeholder="What is your name?" onfocus="this.placeholder = ''" onblur="this.placeholder = 'What is your name?'" value="" name="name">
<br />
<input id="second-input" type="text" pattern="[0-9]*" placeholder="Enter your phone number" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Enter your phone number'" value="" name="phone-number">
<br />
<input id="third-input" type="text" placeholder="Press button and Share location" onfocus="this.placeholder = ''" onblur="this.placeholder = 'Press button and Share location'" value="" disabled="disabled" name="coordinates">
<br />
<input type="submit" value="Send Us Request">
</form>
Here is my jQuery for this form
$('form').submit(function(){
var name = $('#first-input').val();
var telephone = $('#second-input').val();
var location = $('#third-input').val();
if (navigator.geolocation) {
navigator.geolocation.getCurrentPosition(showPosition);
} else {
location.val() = "Geolocation is not supported by this browser.";
}
}
function showPosition(position) {
location.val(position.coords.latitude + ", " + position.coords.longitude);
}
if(name === ''){
$('#first-input').css('border-top', 'solid 5px #ED6D60');
} else {
$('#first-input').css('border-top', 'solid 5px #0ED54D');
}
if(telephone === ''){
$('#second-input').css('border-top', 'solid 5px #ED6D60');
} else {
$('#second-input').css('border-top', 'solid 5px #0ED54D');
}
if(location === ''){
$('#third-input').css('border-top', 'solid 5px #ED6D60');
} else {
$('#third-input').css('border-top', 'solid 5px #0ED54D');
}
return false;
The Geolocation idea I took from this link [http://www.w3schools.com/][1]
As you can see, I am very new to it, but I can promise you that I made a healthy search and didn't find any solution. I would also like to avoid using plugins.
Thanks.
Code with comments is welcome, I just want to be sure "what does what".
[1]: Geolocation on w3schools.com