I want to store the user input from text boxes into variables, changing what is displayed to the user
up vote
-1
down vote
favorite
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
add a comment |
up vote
-1
down vote
favorite
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
"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 at 19:25
let me edit it.
– Alexander Ross Thompson
Nov 13 at 19:25
This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.
– I. R. R.
Nov 13 at 19:27
add a comment |
up vote
-1
down vote
favorite
up vote
-1
down vote
favorite
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
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
javascript
edited Nov 13 at 20:46
Daniel Beck
12.4k31540
12.4k31540
asked Nov 13 at 19:18
Alexander 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 at 19:25
let me edit it.
– Alexander Ross Thompson
Nov 13 at 19:25
This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.
– I. R. R.
Nov 13 at 19:27
add a comment |
"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 at 19:25
let me edit it.
– Alexander Ross Thompson
Nov 13 at 19:25
This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.
– I. R. R.
Nov 13 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 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 at 19:25
let me edit it.
– Alexander Ross Thompson
Nov 13 at 19:25
let me edit it.
– Alexander Ross Thompson
Nov 13 at 19:25
This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.
– I. R. R.
Nov 13 at 19:27
This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.
– I. R. R.
Nov 13 at 19:27
add a comment |
1 Answer
1
active
oldest
votes
up vote
0
down vote
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>
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 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 at 21:00
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
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>
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 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 at 21:00
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
add a comment |
up vote
0
down vote
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>
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 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 at 21:00
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
add a comment |
up vote
0
down vote
up vote
0
down vote
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>
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>
answered Nov 13 at 19:28
Tim ggwp
408311
408311
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 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 at 21:00
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
add a comment |
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 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 at 21:00
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
Hi I've edited my question, as it didn't really make sense first time round.
– Alexander Ross Thompson
Nov 13 at 20:36
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 at 20:50
sorry, did not get what exactly you want
– Tim ggwp
Nov 13 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 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 at 21:00
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
Glad that you figured out.
– Tim ggwp
Nov 13 at 21:02
add a comment |
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.
Some of your past answers have not been well-received, and you're in danger of being blocked from answering.
Please pay close attention to the following guidance:
- 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.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
"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 at 19:25
let me edit it.
– Alexander Ross Thompson
Nov 13 at 19:25
This is the event you are looking for: developer.mozilla.org/en-US/docs/Web/Events/keyup.
– I. R. R.
Nov 13 at 19:27