Parse a value and make it editable in javascript












0















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()">









share|improve this question

























  • So which element are you trying to make editable? what is the HTML supporting this code?

    – Snowmonkey
    Nov 20 '18 at 17:31











  • share that code logic as well

    – Jayanth
    Nov 20 '18 at 17:32











  • How is the code supposed to know whether to divide the input by 30 or not?

    – Barmar
    Nov 20 '18 at 17:34











  • Why don't you use Input tag and give the user to add any value?

    – Dananjaya Ariyasena
    Nov 20 '18 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 '18 at 17:44
















0















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()">









share|improve this question

























  • So which element are you trying to make editable? what is the HTML supporting this code?

    – Snowmonkey
    Nov 20 '18 at 17:31











  • share that code logic as well

    – Jayanth
    Nov 20 '18 at 17:32











  • How is the code supposed to know whether to divide the input by 30 or not?

    – Barmar
    Nov 20 '18 at 17:34











  • Why don't you use Input tag and give the user to add any value?

    – Dananjaya Ariyasena
    Nov 20 '18 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 '18 at 17:44














0












0








0








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()">









share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 20 '18 at 17:41







Navroop

















asked Nov 20 '18 at 17:30









Navroop Navroop

398




398













  • So which element are you trying to make editable? what is the HTML supporting this code?

    – Snowmonkey
    Nov 20 '18 at 17:31











  • share that code logic as well

    – Jayanth
    Nov 20 '18 at 17:32











  • How is the code supposed to know whether to divide the input by 30 or not?

    – Barmar
    Nov 20 '18 at 17:34











  • Why don't you use Input tag and give the user to add any value?

    – Dananjaya Ariyasena
    Nov 20 '18 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 '18 at 17:44



















  • So which element are you trying to make editable? what is the HTML supporting this code?

    – Snowmonkey
    Nov 20 '18 at 17:31











  • share that code logic as well

    – Jayanth
    Nov 20 '18 at 17:32











  • How is the code supposed to know whether to divide the input by 30 or not?

    – Barmar
    Nov 20 '18 at 17:34











  • Why don't you use Input tag and give the user to add any value?

    – Dananjaya Ariyasena
    Nov 20 '18 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 '18 at 17:44

















So which element are you trying to make editable? what is the HTML supporting this code?

– Snowmonkey
Nov 20 '18 at 17:31





So which element are you trying to make editable? what is the HTML supporting this code?

– Snowmonkey
Nov 20 '18 at 17:31













share that code logic as well

– Jayanth
Nov 20 '18 at 17:32





share that code logic as well

– Jayanth
Nov 20 '18 at 17:32













How is the code supposed to know whether to divide the input by 30 or not?

– Barmar
Nov 20 '18 at 17:34





How is the code supposed to know whether to divide the input by 30 or not?

– Barmar
Nov 20 '18 at 17:34













Why don't you use Input tag and give the user to add any value?

– Dananjaya Ariyasena
Nov 20 '18 at 17:37





Why don't you use Input tag and give the user to add any value?

– Dananjaya Ariyasena
Nov 20 '18 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 '18 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 '18 at 17:44












1 Answer
1






active

oldest

votes


















0

















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.






share|improve this answer


























  • code snippet not working

    – Navroop
    Nov 20 '18 at 17:58











  • Then what exactly?

    – Matthi
    Nov 20 '18 at 17:59











  • nothing happens

    – Navroop
    Nov 20 '18 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 '18 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 '18 at 18:14











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%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









0

















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.






share|improve this answer


























  • code snippet not working

    – Navroop
    Nov 20 '18 at 17:58











  • Then what exactly?

    – Matthi
    Nov 20 '18 at 17:59











  • nothing happens

    – Navroop
    Nov 20 '18 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 '18 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 '18 at 18:14
















0

















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.






share|improve this answer


























  • code snippet not working

    – Navroop
    Nov 20 '18 at 17:58











  • Then what exactly?

    – Matthi
    Nov 20 '18 at 17:59











  • nothing happens

    – Navroop
    Nov 20 '18 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 '18 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 '18 at 18:14














0












0








0










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.






share|improve this answer


















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="—">






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 20 '18 at 18:03

























answered Nov 20 '18 at 17:55









MatthiMatthi

592212




592212













  • code snippet not working

    – Navroop
    Nov 20 '18 at 17:58











  • Then what exactly?

    – Matthi
    Nov 20 '18 at 17:59











  • nothing happens

    – Navroop
    Nov 20 '18 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 '18 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 '18 at 18:14



















  • code snippet not working

    – Navroop
    Nov 20 '18 at 17:58











  • Then what exactly?

    – Matthi
    Nov 20 '18 at 17:59











  • nothing happens

    – Navroop
    Nov 20 '18 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 '18 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 '18 at 18:14

















code snippet not working

– Navroop
Nov 20 '18 at 17:58





code snippet not working

– Navroop
Nov 20 '18 at 17:58













Then what exactly?

– Matthi
Nov 20 '18 at 17:59





Then what exactly?

– Matthi
Nov 20 '18 at 17:59













nothing happens

– Navroop
Nov 20 '18 at 18:03





nothing happens

– Navroop
Nov 20 '18 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 '18 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 '18 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 '18 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 '18 at 18:14




















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%2f53398427%2fparse-a-value-and-make-it-editable-in-javascript%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







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)