• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Java Script Reverse Program

 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi I am writing a code to reverse the numbers in a text box provided.
Also When i press the button it should disdplay the numbers in reverse orider:
Please assist as I am not able to display these numbers in revers order:
Here is my code:
function reverse1(windowform1)
{
str = document.windowform1.revtext.value;
for (i = 0; i <= str.length; i++)
text = str.substring(i, i+1) + text;
document.windowform1.revtext.value = text;
}



<INPUT TYPE="text" NAME="revtext" READONLY><BR><BR>
<INPUT TYPE="button" VALUE="REVERSE" onclick="reverse1(this.windowform1)">
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
for (i = 0; i <= str.length; i++)

If you want to reverse the contents of the string, then you will have to start from the other end. i.e.

[ August 18, 2006: Message edited by: jaikiran pai ]
 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi Jaikiran,

Thanks for your immediate reply.
I tried your code the other end but it did not give me the desired result:

Can you help me further?
 
Jaikiran Pai
Marshal
Pie
Posts: 10447
227
IntelliJ IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am not sure why it did not work for you, but here's what you have to do:

 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,

I tried your code but it isn't working for me???
Can you suggest me somethig else so that I can modify your code to get the desired result??

thanks in advance!!!
 
Brijesh Shah
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hey thanks
I managed to get the result...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic