Jump to content

Apply script functions to multiple fields?


Recommended Posts

I have a script forcing numeric characters only in a couple fields (thanks May Music).  

<script>

function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
document.getElementById('InsertRecordFIELD1').onkeypress =isNumberKey;
</script>

 

I had several fields like this so I cheated and created one script for each FIELDNAME (I know, I know, Im still learning  :^).  How could I combine all fields into that one script above?  I tried this but it didnt work:

document.getElementById('InsertRecordFIELD1','InsertRecordFIELD2','InsertRecordFIELD3')

 

Link to comment
Share on other sites

  • 2 weeks later...
On 5/3/2017 at 3:31 PM, roattw said:

I have a script forcing numeric characters only in a couple fields (thanks May Music).  

<script>

function isNumberKey(evt){
    var charCode = (evt.which) ? evt.which : event.keyCode
    if (charCode > 31 && (charCode < 48 || charCode > 57))
        return false;
    return true;
}
document.getElementById('InsertRecordFIELD1').onkeypress =isNumberKey;
</script>

 

I had several fields like this so I cheated and created one script for each FIELDNAME (I know, I know, Im still learning  :^).  How could I combine all fields into that one script above?  I tried this but it didnt work:

document.getElementById('InsertRecordFIELD1','InsertRecordFIELD2','InsertRecordFIELD3')

 

Just write two additional lines which will call function for each field:

document.getElementById('InsertRecordFIELD1').onkeypress =isNumberKey; 

document.getElementById('InsertRecordFIELD2').onkeypress =isNumberKey;

document.getElementById('InsertRecordFIELD3').onkeypress =isNumberKey;

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...