Parse a value and make it editable in javascript
I have a requirement to parse a value in a field but also make it editable so that user can add a value by himself as well which is not dependent on calculation. I am able to parse the value to the field but I am not able to make it editable so that user add a value by himself. Please help.
var Height = document.getElementsByName('[Height]')[0].value;
var vertical = Height / 30;
if (vertical > 1) {
var x = parseInt(vertical);
console.log(x);
document.getElementsByName('vertical')[0].value = x;
} else {
return false;
}
Update
<input type="number" id="message" name="vertical" oninput="calculate()">
javascript
add a comment |
I have a requirement to parse a value in a field but also make it editable so that user can add a value by himself as well which is not dependent on calculation. I am able to parse the value to the field but I am not able to make it editable so that user add a value by himself. Please help.
var Height = document.getElementsByName('[Height]')[0].value;
var vertical = Height / 30;
if (vertical > 1) {
var x = parseInt(vertical);
console.log(x);
document.getElementsByName('vertical')[0].value = x;
} else {
return false;
}
Update
<input type="number" id="message" name="vertical" oninput="calculate()">
javascript
So which element are you trying to make editable? what is the HTML supporting this code?
– Snowmonkey
Nov 20 at 17:31
share that code logic as well
– Jayanth
Nov 20 at 17:32
How is the code supposed to know whether to divide the input by 30 or not?
– Barmar
Nov 20 at 17:34
Why don't you useInput tag
and give the user to add any value?
– Dananjaya Ariyasena
Nov 20 at 17:37
Height is always divided by 30 to get the vertical variable. I have used the input tag on the vertical field but the requirement is it calculated based on height and if we need more vertical user can enter by himself.
– Navroop
Nov 20 at 17:44
add a comment |
I have a requirement to parse a value in a field but also make it editable so that user can add a value by himself as well which is not dependent on calculation. I am able to parse the value to the field but I am not able to make it editable so that user add a value by himself. Please help.
var Height = document.getElementsByName('[Height]')[0].value;
var vertical = Height / 30;
if (vertical > 1) {
var x = parseInt(vertical);
console.log(x);
document.getElementsByName('vertical')[0].value = x;
} else {
return false;
}
Update
<input type="number" id="message" name="vertical" oninput="calculate()">
javascript
I have a requirement to parse a value in a field but also make it editable so that user can add a value by himself as well which is not dependent on calculation. I am able to parse the value to the field but I am not able to make it editable so that user add a value by himself. Please help.
var Height = document.getElementsByName('[Height]')[0].value;
var vertical = Height / 30;
if (vertical > 1) {
var x = parseInt(vertical);
console.log(x);
document.getElementsByName('vertical')[0].value = x;
} else {
return false;
}
Update
<input type="number" id="message" name="vertical" oninput="calculate()">
javascript
javascript
edited Nov 20 at 17:41
asked Nov 20 at 17:30
Navroop
328
328
So which element are you trying to make editable? what is the HTML supporting this code?
– Snowmonkey
Nov 20 at 17:31
share that code logic as well
– Jayanth
Nov 20 at 17:32
How is the code supposed to know whether to divide the input by 30 or not?
– Barmar
Nov 20 at 17:34
Why don't you useInput tag
and give the user to add any value?
– Dananjaya Ariyasena
Nov 20 at 17:37
Height is always divided by 30 to get the vertical variable. I have used the input tag on the vertical field but the requirement is it calculated based on height and if we need more vertical user can enter by himself.
– Navroop
Nov 20 at 17:44
add a comment |
So which element are you trying to make editable? what is the HTML supporting this code?
– Snowmonkey
Nov 20 at 17:31
share that code logic as well
– Jayanth
Nov 20 at 17:32
How is the code supposed to know whether to divide the input by 30 or not?
– Barmar
Nov 20 at 17:34
Why don't you useInput tag
and give the user to add any value?
– Dananjaya Ariyasena
Nov 20 at 17:37
Height is always divided by 30 to get the vertical variable. I have used the input tag on the vertical field but the requirement is it calculated based on height and if we need more vertical user can enter by himself.
– Navroop
Nov 20 at 17:44
So which element are you trying to make editable? what is the HTML supporting this code?
– Snowmonkey
Nov 20 at 17:31
So which element are you trying to make editable? what is the HTML supporting this code?
– Snowmonkey
Nov 20 at 17:31
share that code logic as well
– Jayanth
Nov 20 at 17:32
share that code logic as well
– Jayanth
Nov 20 at 17:32
How is the code supposed to know whether to divide the input by 30 or not?
– Barmar
Nov 20 at 17:34
How is the code supposed to know whether to divide the input by 30 or not?
– Barmar
Nov 20 at 17:34
Why don't you use
Input tag
and give the user to add any value?– Dananjaya Ariyasena
Nov 20 at 17:37
Why don't you use
Input tag
and give the user to add any value?– Dananjaya Ariyasena
Nov 20 at 17:37
Height is always divided by 30 to get the vertical variable. I have used the input tag on the vertical field but the requirement is it calculated based on height and if we need more vertical user can enter by himself.
– Navroop
Nov 20 at 17:44
Height is always divided by 30 to get the vertical variable. I have used the input tag on the vertical field but the requirement is it calculated based on height and if we need more vertical user can enter by himself.
– Navroop
Nov 20 at 17:44
add a comment |
1 Answer
1
active
oldest
votes
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
In this solution, you have an input and output element. On every “oninput” the function will set the output field with the calculated value.
code snippet not working
– Navroop
Nov 20 at 17:58
Then what exactly?
– Matthi
Nov 20 at 17:59
nothing happens
– Navroop
Nov 20 at 18:03
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
|
show 1 more comment
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
});
}
});
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%2f53398427%2fparse-a-value-and-make-it-editable-in-javascript%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
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
In this solution, you have an input and output element. On every “oninput” the function will set the output field with the calculated value.
code snippet not working
– Navroop
Nov 20 at 17:58
Then what exactly?
– Matthi
Nov 20 at 17:59
nothing happens
– Navroop
Nov 20 at 18:03
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
|
show 1 more comment
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
In this solution, you have an input and output element. On every “oninput” the function will set the output field with the calculated value.
code snippet not working
– Navroop
Nov 20 at 17:58
Then what exactly?
– Matthi
Nov 20 at 17:59
nothing happens
– Navroop
Nov 20 at 18:03
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
|
show 1 more comment
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
In this solution, you have an input and output element. On every “oninput” the function will set the output field with the calculated value.
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
In this solution, you have an input and output element. On every “oninput” the function will set the output field with the calculated value.
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
var heightInput = document.getElementById('height'),
verticalOutput = document.getElementById('vertical');
function calculate() {
var vertical = parseInt(heightInput.value,10) / 30;
verticalOutput.value = vertical > 1 ? Math.floor(vertical) : "—";
}
<div>Type in a value greater than 30</div>
<input type="number" id="height" oninput="calculate()">
=>
<input id="vertical" type="number" value="—">
edited Nov 20 at 18:03
answered Nov 20 at 17:55
Matthi
562212
562212
code snippet not working
– Navroop
Nov 20 at 17:58
Then what exactly?
– Matthi
Nov 20 at 17:59
nothing happens
– Navroop
Nov 20 at 18:03
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
|
show 1 more comment
code snippet not working
– Navroop
Nov 20 at 17:58
Then what exactly?
– Matthi
Nov 20 at 17:59
nothing happens
– Navroop
Nov 20 at 18:03
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
code snippet not working
– Navroop
Nov 20 at 17:58
code snippet not working
– Navroop
Nov 20 at 17:58
Then what exactly?
– Matthi
Nov 20 at 17:59
Then what exactly?
– Matthi
Nov 20 at 17:59
nothing happens
– Navroop
Nov 20 at 18:03
nothing happens
– Navroop
Nov 20 at 18:03
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
Type a number greater than 30 (otherwise nothing happens). This is how you presented your code. If not, what should happen?
– Matthi
Nov 20 at 18:04
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
So please type 90. The output value will be 3. Then you can click into the output field and write something totally different. Exactly what you described, isn’t it?
– Matthi
Nov 20 at 18:14
|
show 1 more 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%2f53398427%2fparse-a-value-and-make-it-editable-in-javascript%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
So which element are you trying to make editable? what is the HTML supporting this code?
– Snowmonkey
Nov 20 at 17:31
share that code logic as well
– Jayanth
Nov 20 at 17:32
How is the code supposed to know whether to divide the input by 30 or not?
– Barmar
Nov 20 at 17:34
Why don't you use
Input tag
and give the user to add any value?– Dananjaya Ariyasena
Nov 20 at 17:37
Height is always divided by 30 to get the vertical variable. I have used the input tag on the vertical field but the requirement is it calculated based on height and if we need more vertical user can enter by himself.
– Navroop
Nov 20 at 17:44