Jump to content

Recommended Posts

Does anyone know how to modify this code so that it deny in case a text field is empty? Next to that I want to multiply it by 1.5. Anyone?

onchange="document.getElementById('total').value = parseInt(document.getElementById('f1').value) + parseInt(document.getElementById('f2').value) + parseInt(document.getElementById('f3').value) + parseInt(document.getElementById('f4').value);"

 

thanks a lot in advance!

In your case, I'll make a function that will check the value and return the integer or a 0;

 

e.g.

function my_parse_int(val){
    val = parseInt(val, 10);
    if (isNaN(val)) return 0;
    return val;
};

... change the onchange event to
onchange="document.getElementById('total').value = (my_parse_int(document.getElementById('f1').value) ....) *1.5;

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  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.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.