1

I'm trying to get the values from the and a checkbox, and put the value in a text box OR add the dropdown and checkbox if both are selected and put that into a text box. There is a JavaScript error in the code, which you can see in the link below, in IE but it works correctly in Chrome. Any guidance on this?

function TotAmt() {
   var DA = +document.getElementById("Donation").options[Donation.selectedIndex].value;
   if (document.form1.somename.checked == true) {
      document.form1.Summary.value = parseInt(DA) + parseInt(500);
   } else {
      document.form1.Summary.value = parseInt(DA);
   }
}

View sample code

0

1 Answer 1

2

You get rid of that specific error in jsFiddle by not wrapping the javascript in the head. Then use getElementById function in your ToAtm() function like this:

function fnchecked(blnchecked) {
    if (blnchecked) {
        document.getElementById("CoatSizeDiv").style.display = "";
    } else {
        document.getElementById("CoatSizeDiv").style.display = "none";
    }
}

function TotAmt() {
    var DA = +document.getElementById("Donation").options[Donation.selectedIndex].value;
    if (document.getElementById("somename").checked == true) {
        document.getElementById("Summary").value = parseInt(DA) + parseInt(500);
    } else {
        document.getElementById("Summary").value = parseInt(DA);
    }
}

UPDATED CODE

Sign up to request clarification or add additional context in comments.

7 Comments

You're right, I should have used the getElementByID. So you're saying these JS functions should not be in the head, but in the body?
No, for them to work in jaFiddle you need to remove the wrapper. I would personally put these in the head.
Thanks for the help. I can get the code working in Chrome and FireFox on my website but IE isn't doing anything and is not show any errors. Good old IE. LOL
I keep having it show this error "SCRIPT5009: 'Donation' is undefined " and it points to the line that starts with "var DA = ...."
That's what it was. Thanks!
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.