0

okay, I have two radio buttons on a web page with two different functions but the second is not working. So my code looks like the following:

<input onclick='fillShipping();' name='address' type="radio" id='same'>Use Address for Shipping<br>
<input onclick='clear();' name='address' type="radio" id='different'>Use Seperate Address for Shipping

The first function, with the onclick event, works perfectly fine. The second function, named clear(), does not fire. Nothing happens at all. I'm not quite sure why this is happening.

The code for the clear function is the following:

function clear() {
    if (document.getElementById('different').checked){
       alert('Hi');
   }
}

Nothing fancy and yet nothing happens. Am I missing something basic with using radio buttons and functions?

j08691
  • 204,283
  • 31
  • 260
  • 272
ravenUSMC
  • 495
  • 5
  • 23

2 Answers2

0

I'm wondering if there is another "clear" function that is being called instead of the one you're expecting - try changing the function name to "clearTest".

combatc2
  • 1,215
  • 10
  • 10
  • Yeah that worked! But I had no other function named clear-maybe a keyword in JavaScript? Thank you for the help! – ravenUSMC Nov 09 '17 at 22:01
0

The issue is the name clear. You will have to use another name. You are actually calling document.clear() instead of your global clear()

link0047
  • 103
  • 7