开发者

Is there any logical purpose for this javascript beyond what I can evaluate?

开发者 https://www.devze.com 2023-03-02 04:44 出处:网络
Here are the snippets from one of our pages.It\'s my opinion that this is terribly complex, confusing, and flawed in it\'s design.For one thing, it causes a message in IE that the page is trying to ac

Here are the snippets from one of our pages. It's my opinion that this is terribly complex, confusing, and flawed in it's design. For one thing, it causes a message in IE that the page is trying to access the clipboard. Is there something I'm missing?

I guess my question is; Is it okay to think that this is complete overkill? Do I have a right to be frustrated? Or am I oblivious to some higher knowledge?

function NoEmailGiven(){

    var copyval

    document.frm1.NoEmail.focus();
    document.frm1.NoEmail.select();
    copyval=document.SCPACALL.NoEmail.createTextRange();
    copyval.execCommand('开发者_C百科Copy');
    document.frm1.Email1.focus();
    document.frm1.Email1.select();
    document.execCommand('Paste');
    document.frm1.Email2.focus();
    document.frm1.Email2.select();
    document.execCommand('Paste');

}

response.write "<INPUT TYPE=button name=NoEmail VALUE=""None"" Title=""Click if No Email Address"" ONCLICK=""NoEmailGiven""></td></tr>"
  • Here is what the page is supposed to do..

If the user clicks the button labeled "Click here if no email address" then auto populate Email1 & Email2 with the literal string 'None'

  • Here is the pseudocode as I have figured it out from the page usage of what it actually does.

If the user clicks the button labeled "Click here if no email address" copy the value of this button which is "None" into the client's clipboard, then paste from the clipboard into Email1 & Email2

  • Finally: What I would have written (Only to duplicate the process, not improve or change the form to the users)

    function NoEmailGiven() { Email1.value = "None"; Email2.value = "None"; }


Yes, this is a stupid way to do this. They obviously didn't know what they were doing and have not realised that copy and paste is a user orientated concept, whereas copying the value of one field to another using code more sense.

I'd delete it and rewrite it!


I'm assuming that what they're trying to do is copy data from one field to another. In jQuery, that would be:

var NO_EMAIL = '.....';
function NoEmailGiven() {
    $('#Email1').val(NO_EMAIL);
    $('#Email2').val(NO_EMAIL);
}
0

精彩评论

暂无评论...
验证码 换一张
取 消