Moti Mashiah
asked on
javascript
Hi guys,
I'm really beginner to javascript and I would like to know how do I write some result to the textarea.
Here is what I'm trying to do:
so instead to write to "document.write(start + "<br/>"); i would like to write the result to the variable I prepared which is my textarea - "var txtare = document.getElementById("n umd").valu e;"
thanks ,
I'm really beginner to javascript and I would like to know how do I write some result to the textarea.
Here is what I'm trying to do:
function lopwhil() {
var target = Number(prompt("Please enter number max (100)"))
var txtare = document.getElementById("numd").value;
var wrto = start + "<br/>";
var start = 0;
while (start <= target) {
document.write(start + "<br/>");
start = start + 2;
if (start > 100)
break;
}
}
so instead to write to "document.write(start + "<br/>"); i would like to write the result to the variable I prepared which is my textarea - "var txtare = document.getElementById("n
thanks ,
change variable textare so it refers to the textarea rather than the textarea value:
to :
then change the document write :
so you end up with:
var txtare = document.getElementById("numd").value;
to :
var txtare = document.getElementById("numd");
then change the document write :
...
while (start <= target) {
textare.value = start + "<br/>";
...
so you end up with:
function lopwhil() {
var target = Number(prompt("Please enter number max (100)"))
var txtare = document.getElementById("numd");
var wrto = start + "<br/>";
var start = 0;
while (start <= target) {
textare.value = start + "<br/>";
start = start + 2;
if (start > 100)
break;
}
ASKER
I have changed the code as your suggestion and I got just one value in the textarea. for example in the prompt window I typed 50 and entered so in this case i should get back the number 2,4,6,8 until 50 so i got just 50<br/> to the textarea,
Now i was trying to loop it and get the same result.
please help thanks ,
Now i was trying to loop it and get the same result.
function lopech() {
var target = Number(prompt("Please enter number max (100)"))
var txtare = document.getElementById("numd");
for(var start = 0; start <= target; start = start + 2 ){
txtare.value = (start + "<br/>");
if (start > 100)
break;
}
}
please help thanks ,
Hi,
this is due to the fact that you always overwrite the textarea.
This should fix it:
HTH
Rainer
this is due to the fact that you always overwrite the textarea.
This should fix it:
function lopech() {
var target = Number(prompt("Please enter number max (100)"))
var txtare = document.getElementById("numd");
for(var start = 0; start <= target; start = start + 2 ){
txtare.value = (""+ txtare.value + start + "<br/>");
if (start > 100)
break;
}
}
HTH
Rainer
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
Hi guys ,
thank you for you solution it is working now, just the result show also the break
like:
0<br/>2<br/>4<br/>6<br/>8< br/>10<br/ >12<br/>14 <br/>16<br />18<br/>2 0<br/>22<b r/>24<br/> 26<br/>28< br/>30<br/ >32<br/>34 <br/>36<br />38<br/>4 0<br/>42<b r/>44<br/> 46<br/>48< br/>50<br/ >
Here is the code:
thank you for you solution it is working now, just the result show also the break
like:
0<br/>2<br/>4<br/>6<br/>8<
Here is the code:
function lopech() {
var target = Number(prompt("Please enter number max (100)"));
var txtare = document.getElementById("numd");
for (var start = 0; start <= target; start = start + 2) {
txtare.value = ("" + txtare.value + start + "<br/>");
if (start > 100)
break;
}
}
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
k, I found the solution regarding the line
txtare.value = (""+ txtare.value + start + "\n");
thank you.
txtare.value = (""+ txtare.value + start + "\n");
thank you.
ASKER
solved
http://www.jquerytutorials.net/jquery-textarea.html