Reputation: 723
I am making an application using jQuery. In my app, the user enters some input like:
"We are going to party"
and when he clicks on the convert button, the result should be:
"V R GNG 2 PRTY".
But in my code, I am getting only last value as a result.
The code is at pastebin.com/NWMavENb.
I want the result to be "V R GNG 2 PRTY".Here is my page you can download http://www.mediafire.com/?cj5lz68di25dzx22 this page.
Upvotes: 0
Views: 64
Reputation: 3986
You are simply changing the value every time, so only the last value is stored. You need to keep track of the value and append to it.
Here is one way
if(words[i]=="Are"||words[i]=="are"||words[i]=="ARE")
{
$("#cnvalue").val($("#cnvalue").val() + " R");
}
Upvotes: 0
Reputation: 5579
For each of your conditional if
tests (and yes there are many ways to do this), try
if(words[i].toLowerCase() == "going") // case-insensitive test
{
words[i] = "GNG";
}
and then after the end of your loop, reassign the value to your destination element.
$("#cnvalue").val(words.join(' '));
Upvotes: 1