string to ascii javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • kshetarpal
    New Member
    • Feb 2008
    • 1

    string to ascii javascript

    I have the following code for converting string to ascii but I would like to add the values. The following code does not add the values;

    [CODE=javascript]var str = owner.value
    var code
    strLength = owner.value.len gth
    for (i =0;i<strLength; i++){
    code = str.charCodeAt( i);

    alert(code);
    [/CODE]
    I would appreciate any help.

    Kshetarpal
    Last edited by gits; Feb 7 '08, 05:34 PM. Reason: added code tags
  • gits
    Recognized Expert Moderator Expert
    • May 2007
    • 5390

    #2
    how would you add the values? simply adding them could be done with the following example:

    [CODE=javascript]var str = 'abcd';
    var code = 0;
    var strLength = str.length;

    for (var i = 0; i < strLength; i++) {
    code += parseInt(str.ch arCodeAt(i), 10);
    }

    alert(code);
    [/CODE]
    kind regards

    Comment

    Working...