Can we print loop output in same page. | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 1

Can we print loop output in same page.

Like we have html page inside that we have input tag for taking input from user and that input value is going to be used in loop as well, And after some calculations done by loop the output will be printed next to input in another div in same html page. Is it possible !! Souce code: https://code.sololearn.com/W7gYdfXr455J/?ref=app

2nd May 2020, 11:01 AM
Ashutosh
Ashutosh - avatar
18 Answers
+ 4
Hey there Ashu, here is the fixed code: https://code.sololearn.com/WsRm6k9V12eA/?ref=app Just remove the innerHTML from the variable itself and use '+=' instead of '='; You were overwriting the document again, that's why the result was being shown in a new page!
2nd May 2020, 12:09 PM
Arb Rahim Badsa
Arb Rahim Badsa - avatar
+ 4
Yes use innerHTML property for that .
2nd May 2020, 11:11 AM
Ayush Kumar
Ayush Kumar - avatar
+ 3
https://code.sololearn.com/W0AVEua3MZ13/?ref=app See for sample I had used innerHTML property with functions.
2nd May 2020, 11:29 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Ok just share your source code so that we can modify it
2nd May 2020, 11:31 AM
Ayush Kumar
Ayush Kumar - avatar
+ 2
Hay Ashu . Arb Rahim Badsa bro has done it for you .
2nd May 2020, 12:17 PM
Ayush Kumar
Ayush Kumar - avatar
+ 1
Use javascript to get the value from input. Make a variable like $var=document.getElementById('textbox_id').value Then use this variable for calculation and then return it's value in the same textbox or into another one.
2nd May 2020, 11:19 AM
Vishal Srivastava
Vishal Srivastava - avatar
+ 1
Are you using any eventlistner?
2nd May 2020, 11:26 AM
Vishal Srivastava
Vishal Srivastava - avatar
+ 1
Use js event like onclick ....then use innerhtml then that function will run with automatically changed value on the same page
2nd May 2020, 11:26 AM
Vishal Srivastava
Vishal Srivastava - avatar
+ 1
You can also do this you can store the text field value in variable ... Do you calculation store in new variable, create a onclick or oninput function then return it's value using the document.getelementbyid('').value= new variable value; Share your code if you still have problem we can help you out
2nd May 2020, 11:39 AM
Vishal Srivastava
Vishal Srivastava - avatar
+ 1
Thank you guys. #Auysh #Vishal #Rahim
2nd May 2020, 12:21 PM
Ashutosh
Ashutosh - avatar
+ 1
Thank you so much bro #Arb rahim badsa
2nd May 2020, 12:21 PM
Ashutosh
Ashutosh - avatar
0
But after using InnerHTML property Output print in another page not in same page bro. I am looking that output should print in a same page in one particular div. #Ayush. ks
2nd May 2020, 11:22 AM
Ashutosh
Ashutosh - avatar
0
How should I return loop output, In my case it only print last line of loop. #vishal
2nd May 2020, 11:30 AM
Ashutosh
Ashutosh - avatar
0
Yes bro i use eventListner Onclick.
2nd May 2020, 11:36 AM
Ashutosh
Ashutosh - avatar
0
Ok wait I will show my work
2nd May 2020, 11:46 AM
Ashutosh
Ashutosh - avatar
2nd May 2020, 11:49 AM
Ashutosh
Ashutosh - avatar
0
Got It... So you're trying to return a whole sequence of table in your html box
2nd May 2020, 12:16 PM
Vishal Srivastava
Vishal Srivastava - avatar
0
@Arb Rahim. Not thought of that actually. I tried using an array to store the value of the loop, it worked but retrieving all the values in a same textbox was the challenge. It was only retrieving the final value. But somehow it worked. But you did great work. Appreciated.
2nd May 2020, 1:07 PM
Vishal Srivastava
Vishal Srivastava - avatar