- Back to Home »
- JAVASCRIPT »
- Scramble word in javascript
Posted by : ஆனந்த் சதாசிவம்
Friday, January 4, 2013
Scramble Function
function scramble(str)
{
var scrambled = '',
src = str.split(''),
randomNum;
while (src.length > 1)
{
randomNum = Math.floor(Math.random() * src.length);
scrambled += src[randomNum];
src.splice(randomNum, 1);
}
scrambled += src[0];
return scrambled;
}
function scram(txt1,txt2 )
{
txt1.value=scramble(txt2.value);
}
Call the Function In aspx page
<asp:Button ID="Button4" runat="server" CssClass="input" Width="200px" Text="Scramble" OnClientClick="scram(document.getElementById('ctl00_ContentPlaceHolder1_txt_us_scr4'), document.getElementById('ctl00_ContentPlaceHolder1_txt_us_ans4'))" />