I want to store the user input from text boxes into variables, changing what is displayed to the user










-1















HTML - There is currently two text input fields followed by a "check" button.



There is then a dropdown selection, with some predetermined locations.



<h4 class="subhead">Enter Coordinates of location</h4>
<label for="la" id="label1">Latitude</label>
<input type="text" name="coords" id="la" class="inputtext" placeholder="example: 53.48"><br>
<br>
<label for="Lo" id="label2">Longitude</label>
<input type="text" name="coords" id="lo" class="inputtext" placeholder="example: -2.24"><br>
<button id="check">Check</button>

<h4 class="subhead">Or select below</h4>
<select id="dropdown">
<option value="manchester" id="manchester" >Manchester</option>
<option value="hongkong" id="hongkong">Hong Kong</option>
<option value="london" id="london">London</option>
<option value="paris" id="paris">Paris</option>
<option value="berlin" id="berlin">Berlin</option>
<option value="nyc" id="nyc">New York</option>
<option value="kl" id="kl">Kuala Lumpur</option>
</select>


JavaScript - I currently have an if statement that checks if the text boxes are empty strings"". If they are empty, it checks what dropdown is selected. There is an event listener to check for the selected dropdown. When one is selected, the weather() function is called and takes latitude and longitude coordinates as arguments, in this case I have entered the actual numeric values because they are predetermined via google search. The dropdown part currently works fine.



 checked(); 
document.getElementById("dropdown").addEventListener("change", checked);
function checked()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(la, lo);
else if (document.getElementById('dropdown').value == "manchester")
weather(53.48, -2.24);
else if (document.getElementById('dropdown').value == "hongkong")
weather(22.2855, 114.157);
else if (document.getElementById('dropdown').value == "london")
weather(51.5074, -0.12);
else if (document.getElementById('dropdown').value == "paris")
weather(48.85, 2.35);
else if (document.getElementById('dropdown').value == "berlin")
weather(52.520007, 13.404954);
else if (document.getElementById('dropdown').value == "nyc")
weather(40.7128, -74.0060);
else if (document.getElementById('dropdown').value == "kl")
weather(3.1390, 101.6869);




I currently don't know how to make the text box coordinates part work. My ideal result is to have the user type in a latitude value and a longitude value, press the check button, and then the values of whatever they input is stored in the variables la and lo.



When this happens, the first stage of the conditional statements will run, because the values in the text boxes are no longer = to an empty string "".



It will then call the weather function with arguments (la, lo) which will be input by the user.



In summary, I want the check button to submit the input values to variables la and lo without reloading the page. Then run the checked function again, which will execute the first if statement, calling the weather function with latitude and longitude coordinates selected by the user.



Sorry if this is confusing, I'm new to this.










share|improve this question
























  • "variables la and lo to be updated real time..." where do you define those variables and where you set its values? It would be good if you add more relevant code, currently, I think your question is a little too hard to understand your desired result

    – Calvin Nunes
    Nov 13 '18 at 19:25











  • let me edit it.

    – Alexander Ross Thompson
    Nov 13 '18 at 19:25











  • This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.

    – Iskandar Reza Razali
    Nov 13 '18 at 19:27
















-1















HTML - There is currently two text input fields followed by a "check" button.



There is then a dropdown selection, with some predetermined locations.



<h4 class="subhead">Enter Coordinates of location</h4>
<label for="la" id="label1">Latitude</label>
<input type="text" name="coords" id="la" class="inputtext" placeholder="example: 53.48"><br>
<br>
<label for="Lo" id="label2">Longitude</label>
<input type="text" name="coords" id="lo" class="inputtext" placeholder="example: -2.24"><br>
<button id="check">Check</button>

<h4 class="subhead">Or select below</h4>
<select id="dropdown">
<option value="manchester" id="manchester" >Manchester</option>
<option value="hongkong" id="hongkong">Hong Kong</option>
<option value="london" id="london">London</option>
<option value="paris" id="paris">Paris</option>
<option value="berlin" id="berlin">Berlin</option>
<option value="nyc" id="nyc">New York</option>
<option value="kl" id="kl">Kuala Lumpur</option>
</select>


JavaScript - I currently have an if statement that checks if the text boxes are empty strings"". If they are empty, it checks what dropdown is selected. There is an event listener to check for the selected dropdown. When one is selected, the weather() function is called and takes latitude and longitude coordinates as arguments, in this case I have entered the actual numeric values because they are predetermined via google search. The dropdown part currently works fine.



 checked(); 
document.getElementById("dropdown").addEventListener("change", checked);
function checked()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(la, lo);
else if (document.getElementById('dropdown').value == "manchester")
weather(53.48, -2.24);
else if (document.getElementById('dropdown').value == "hongkong")
weather(22.2855, 114.157);
else if (document.getElementById('dropdown').value == "london")
weather(51.5074, -0.12);
else if (document.getElementById('dropdown').value == "paris")
weather(48.85, 2.35);
else if (document.getElementById('dropdown').value == "berlin")
weather(52.520007, 13.404954);
else if (document.getElementById('dropdown').value == "nyc")
weather(40.7128, -74.0060);
else if (document.getElementById('dropdown').value == "kl")
weather(3.1390, 101.6869);




I currently don't know how to make the text box coordinates part work. My ideal result is to have the user type in a latitude value and a longitude value, press the check button, and then the values of whatever they input is stored in the variables la and lo.



When this happens, the first stage of the conditional statements will run, because the values in the text boxes are no longer = to an empty string "".



It will then call the weather function with arguments (la, lo) which will be input by the user.



In summary, I want the check button to submit the input values to variables la and lo without reloading the page. Then run the checked function again, which will execute the first if statement, calling the weather function with latitude and longitude coordinates selected by the user.



Sorry if this is confusing, I'm new to this.










share|improve this question
























  • "variables la and lo to be updated real time..." where do you define those variables and where you set its values? It would be good if you add more relevant code, currently, I think your question is a little too hard to understand your desired result

    – Calvin Nunes
    Nov 13 '18 at 19:25











  • let me edit it.

    – Alexander Ross Thompson
    Nov 13 '18 at 19:25











  • This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.

    – Iskandar Reza Razali
    Nov 13 '18 at 19:27














-1












-1








-1








HTML - There is currently two text input fields followed by a "check" button.



There is then a dropdown selection, with some predetermined locations.



<h4 class="subhead">Enter Coordinates of location</h4>
<label for="la" id="label1">Latitude</label>
<input type="text" name="coords" id="la" class="inputtext" placeholder="example: 53.48"><br>
<br>
<label for="Lo" id="label2">Longitude</label>
<input type="text" name="coords" id="lo" class="inputtext" placeholder="example: -2.24"><br>
<button id="check">Check</button>

<h4 class="subhead">Or select below</h4>
<select id="dropdown">
<option value="manchester" id="manchester" >Manchester</option>
<option value="hongkong" id="hongkong">Hong Kong</option>
<option value="london" id="london">London</option>
<option value="paris" id="paris">Paris</option>
<option value="berlin" id="berlin">Berlin</option>
<option value="nyc" id="nyc">New York</option>
<option value="kl" id="kl">Kuala Lumpur</option>
</select>


JavaScript - I currently have an if statement that checks if the text boxes are empty strings"". If they are empty, it checks what dropdown is selected. There is an event listener to check for the selected dropdown. When one is selected, the weather() function is called and takes latitude and longitude coordinates as arguments, in this case I have entered the actual numeric values because they are predetermined via google search. The dropdown part currently works fine.



 checked(); 
document.getElementById("dropdown").addEventListener("change", checked);
function checked()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(la, lo);
else if (document.getElementById('dropdown').value == "manchester")
weather(53.48, -2.24);
else if (document.getElementById('dropdown').value == "hongkong")
weather(22.2855, 114.157);
else if (document.getElementById('dropdown').value == "london")
weather(51.5074, -0.12);
else if (document.getElementById('dropdown').value == "paris")
weather(48.85, 2.35);
else if (document.getElementById('dropdown').value == "berlin")
weather(52.520007, 13.404954);
else if (document.getElementById('dropdown').value == "nyc")
weather(40.7128, -74.0060);
else if (document.getElementById('dropdown').value == "kl")
weather(3.1390, 101.6869);




I currently don't know how to make the text box coordinates part work. My ideal result is to have the user type in a latitude value and a longitude value, press the check button, and then the values of whatever they input is stored in the variables la and lo.



When this happens, the first stage of the conditional statements will run, because the values in the text boxes are no longer = to an empty string "".



It will then call the weather function with arguments (la, lo) which will be input by the user.



In summary, I want the check button to submit the input values to variables la and lo without reloading the page. Then run the checked function again, which will execute the first if statement, calling the weather function with latitude and longitude coordinates selected by the user.



Sorry if this is confusing, I'm new to this.










share|improve this question
















HTML - There is currently two text input fields followed by a "check" button.



There is then a dropdown selection, with some predetermined locations.



<h4 class="subhead">Enter Coordinates of location</h4>
<label for="la" id="label1">Latitude</label>
<input type="text" name="coords" id="la" class="inputtext" placeholder="example: 53.48"><br>
<br>
<label for="Lo" id="label2">Longitude</label>
<input type="text" name="coords" id="lo" class="inputtext" placeholder="example: -2.24"><br>
<button id="check">Check</button>

<h4 class="subhead">Or select below</h4>
<select id="dropdown">
<option value="manchester" id="manchester" >Manchester</option>
<option value="hongkong" id="hongkong">Hong Kong</option>
<option value="london" id="london">London</option>
<option value="paris" id="paris">Paris</option>
<option value="berlin" id="berlin">Berlin</option>
<option value="nyc" id="nyc">New York</option>
<option value="kl" id="kl">Kuala Lumpur</option>
</select>


JavaScript - I currently have an if statement that checks if the text boxes are empty strings"". If they are empty, it checks what dropdown is selected. There is an event listener to check for the selected dropdown. When one is selected, the weather() function is called and takes latitude and longitude coordinates as arguments, in this case I have entered the actual numeric values because they are predetermined via google search. The dropdown part currently works fine.



 checked(); 
document.getElementById("dropdown").addEventListener("change", checked);
function checked()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(la, lo);
else if (document.getElementById('dropdown').value == "manchester")
weather(53.48, -2.24);
else if (document.getElementById('dropdown').value == "hongkong")
weather(22.2855, 114.157);
else if (document.getElementById('dropdown').value == "london")
weather(51.5074, -0.12);
else if (document.getElementById('dropdown').value == "paris")
weather(48.85, 2.35);
else if (document.getElementById('dropdown').value == "berlin")
weather(52.520007, 13.404954);
else if (document.getElementById('dropdown').value == "nyc")
weather(40.7128, -74.0060);
else if (document.getElementById('dropdown').value == "kl")
weather(3.1390, 101.6869);




I currently don't know how to make the text box coordinates part work. My ideal result is to have the user type in a latitude value and a longitude value, press the check button, and then the values of whatever they input is stored in the variables la and lo.



When this happens, the first stage of the conditional statements will run, because the values in the text boxes are no longer = to an empty string "".



It will then call the weather function with arguments (la, lo) which will be input by the user.



In summary, I want the check button to submit the input values to variables la and lo without reloading the page. Then run the checked function again, which will execute the first if statement, calling the weather function with latitude and longitude coordinates selected by the user.



Sorry if this is confusing, I'm new to this.







javascript






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 13 '18 at 20:46









Daniel Beck

12.7k41642




12.7k41642










asked Nov 13 '18 at 19:18









Alexander Ross ThompsonAlexander Ross Thompson

154




154












  • "variables la and lo to be updated real time..." where do you define those variables and where you set its values? It would be good if you add more relevant code, currently, I think your question is a little too hard to understand your desired result

    – Calvin Nunes
    Nov 13 '18 at 19:25











  • let me edit it.

    – Alexander Ross Thompson
    Nov 13 '18 at 19:25











  • This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.

    – Iskandar Reza Razali
    Nov 13 '18 at 19:27


















  • "variables la and lo to be updated real time..." where do you define those variables and where you set its values? It would be good if you add more relevant code, currently, I think your question is a little too hard to understand your desired result

    – Calvin Nunes
    Nov 13 '18 at 19:25











  • let me edit it.

    – Alexander Ross Thompson
    Nov 13 '18 at 19:25











  • This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.

    – Iskandar Reza Razali
    Nov 13 '18 at 19:27

















"variables la and lo to be updated real time..." where do you define those variables and where you set its values? It would be good if you add more relevant code, currently, I think your question is a little too hard to understand your desired result

– Calvin Nunes
Nov 13 '18 at 19:25





"variables la and lo to be updated real time..." where do you define those variables and where you set its values? It would be good if you add more relevant code, currently, I think your question is a little too hard to understand your desired result

– Calvin Nunes
Nov 13 '18 at 19:25













let me edit it.

– Alexander Ross Thompson
Nov 13 '18 at 19:25





let me edit it.

– Alexander Ross Thompson
Nov 13 '18 at 19:25













This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.

– Iskandar Reza Razali
Nov 13 '18 at 19:27






This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.

– Iskandar Reza Razali
Nov 13 '18 at 19:27













1 Answer
1






active

oldest

votes


















0














If it is question about assigning value to variables then:



var la, lo;

function update()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(document.getElementById('la').value, document.getElementById('lo').value);



function weather(x, y)
la = x;
lo = y;



And HTML



<button id="check" onclick="update()">Check</button>





share|improve this answer























  • Hi I've edited my question, as it didn't really make sense first time round.

    – Alexander Ross Thompson
    Nov 13 '18 at 20:36











  • sorry, did not get what exactly you want

    – Antihype Bird
    Nov 13 '18 at 20:50











  • I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

    – Alexander Ross Thompson
    Nov 13 '18 at 21:00











  • Glad that you figured out.

    – Antihype Bird
    Nov 13 '18 at 21:02










Your Answer






StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");

StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);

else
createEditor();

);

function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);



);













draft saved

draft discarded


















StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288075%2fi-want-to-store-the-user-input-from-text-boxes-into-variables-changing-what-is%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









0














If it is question about assigning value to variables then:



var la, lo;

function update()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(document.getElementById('la').value, document.getElementById('lo').value);



function weather(x, y)
la = x;
lo = y;



And HTML



<button id="check" onclick="update()">Check</button>





share|improve this answer























  • Hi I've edited my question, as it didn't really make sense first time round.

    – Alexander Ross Thompson
    Nov 13 '18 at 20:36











  • sorry, did not get what exactly you want

    – Antihype Bird
    Nov 13 '18 at 20:50











  • I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

    – Alexander Ross Thompson
    Nov 13 '18 at 21:00











  • Glad that you figured out.

    – Antihype Bird
    Nov 13 '18 at 21:02















0














If it is question about assigning value to variables then:



var la, lo;

function update()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(document.getElementById('la').value, document.getElementById('lo').value);



function weather(x, y)
la = x;
lo = y;



And HTML



<button id="check" onclick="update()">Check</button>





share|improve this answer























  • Hi I've edited my question, as it didn't really make sense first time round.

    – Alexander Ross Thompson
    Nov 13 '18 at 20:36











  • sorry, did not get what exactly you want

    – Antihype Bird
    Nov 13 '18 at 20:50











  • I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

    – Alexander Ross Thompson
    Nov 13 '18 at 21:00











  • Glad that you figured out.

    – Antihype Bird
    Nov 13 '18 at 21:02













0












0








0







If it is question about assigning value to variables then:



var la, lo;

function update()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(document.getElementById('la').value, document.getElementById('lo').value);



function weather(x, y)
la = x;
lo = y;



And HTML



<button id="check" onclick="update()">Check</button>





share|improve this answer













If it is question about assigning value to variables then:



var la, lo;

function update()
if (document.getElementById('la').value != "" && document.getElementById('lo').value != "")
weather(document.getElementById('la').value, document.getElementById('lo').value);



function weather(x, y)
la = x;
lo = y;



And HTML



<button id="check" onclick="update()">Check</button>






share|improve this answer












share|improve this answer



share|improve this answer










answered Nov 13 '18 at 19:28









Antihype BirdAntihype Bird

436312




436312












  • Hi I've edited my question, as it didn't really make sense first time round.

    – Alexander Ross Thompson
    Nov 13 '18 at 20:36











  • sorry, did not get what exactly you want

    – Antihype Bird
    Nov 13 '18 at 20:50











  • I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

    – Alexander Ross Thompson
    Nov 13 '18 at 21:00











  • Glad that you figured out.

    – Antihype Bird
    Nov 13 '18 at 21:02

















  • Hi I've edited my question, as it didn't really make sense first time round.

    – Alexander Ross Thompson
    Nov 13 '18 at 20:36











  • sorry, did not get what exactly you want

    – Antihype Bird
    Nov 13 '18 at 20:50











  • I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

    – Alexander Ross Thompson
    Nov 13 '18 at 21:00











  • Glad that you figured out.

    – Antihype Bird
    Nov 13 '18 at 21:02
















Hi I've edited my question, as it didn't really make sense first time round.

– Alexander Ross Thompson
Nov 13 '18 at 20:36





Hi I've edited my question, as it didn't really make sense first time round.

– Alexander Ross Thompson
Nov 13 '18 at 20:36













sorry, did not get what exactly you want

– Antihype Bird
Nov 13 '18 at 20:50





sorry, did not get what exactly you want

– Antihype Bird
Nov 13 '18 at 20:50













I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

– Alexander Ross Thompson
Nov 13 '18 at 21:00





I worked it out now. Thanks for trying to help. Your solution was actually perfect for the code i initially shared, but i failed to include some key stuff that meant it wouldn't work.

– Alexander Ross Thompson
Nov 13 '18 at 21:00













Glad that you figured out.

– Antihype Bird
Nov 13 '18 at 21:02





Glad that you figured out.

– Antihype Bird
Nov 13 '18 at 21:02

















draft saved

draft discarded
















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid


  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.

To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53288075%2fi-want-to-store-the-user-input-from-text-boxes-into-variables-changing-what-is%23new-answer', 'question_page');

);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







這個網誌中的熱門文章

How to read a connectionString WITH PROVIDER in .NET Core?

In R, how to develop a multiplot heatmap.2 figure showing key labels successfully

Museum of Modern and Contemporary Art of Trento and Rovereto