/    Sign up×
Community /Pin to ProfileBookmark

Javascript question on reset and onfocus

  • 1. How to reset textbox + textarea?

  • 2. How to make the “function getKeyValue_h(chr)” work without the submit button? (on pasting in textarea it should automatically give the calculated result in the textbox.)
  • JavaScript:

    [code]
    <!–
    //&&& 1st of 2 instances of getKeyValue(). changed name of Fx, ‘_h’ for hebrew?
    function getKeyValue_h(chr) {
    chr=chr.charAt();
    if(chr==”A”) return 1;
    if(chr==”B”) return 2;
    if(chr==”G”) return 3;
    if(chr==”D”) return 4;
    if(chr==”H”) return 5;
    if(chr==”V”) return 6;
    if(chr==”X”) return 8;
    if(chr==”+”) return 9;
    if(chr==”Y”) return 10;
    if(chr==”k” || chr==”K”) return 20;
    if(chr==”L”) return 30;
    if(chr==”m” || chr==”M”) return 40;
    if(chr==”n” || chr==”N”) return 50;
    if(chr==”$”) return 60;
    if(chr==”O”) return 70;
    if(chr==”p” || chr==”P”) return 80;
    if(chr==”c” || chr==”C”) return 90;
    if(chr==”q”) return 100;
    if(chr==”R”) return 200;
    if(chr==”S”) return 300;
    if(chr==”T”) return 400;
    return 0;
    }

    function computeValue(str) {
    var ans=0;
    for(var i=0; i<str.length; i++) {
    ans+=getKeyValue(str.charAt(i));
    }
    return ans;
    }
    //–>
    [/code]

    Within <body> (does it have to be in a form too?):

    [code]
    <br><font face=”BSTHebrew”>
    <textarea name=”hInput” id=”hInput” rows=”9″ cols=”64″
    class=”onLoad” onmouseover=”this.className=’onMouseOver'”
    onmouseout=”this.className=’onMouseOut'”>
    </textarea></font><br>

    <input type=”button” value=”calculate value” onclick=”javascript:computeValue(document.all.hInput.value, ‘h’);”>

    <input type=”reset” value=”Clear” name=”B2″>

    <input type=”text” name=”hOutput” id=”hOutput” readonly=”true”>
    [/code]

    to post a comment
    JavaScript

    0Be the first to comment 😎

    ×

    Success!

    Help @gilgalbiblewhee spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 5.6,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,

    tipper: @Yussuf4331,
    tipped: article
    amount: 1000 SATS,

    tipper: @darkwebsites540,
    tipped: article
    amount: 10 SATS,
    )...