2 Replies - 1012 Views - Last Post: 02 September 2010 - 05:06 PM

#1 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Simple Script runs on IE and Chrome but not FF

Posted 02 September 2010 - 12:52 PM

Hello, I am fairly new to javascript but I have some programming experience. This simple javascript will run on IE and Chrome just fine, but if I try to run it on Firefox it does nothing. If I check FF error console it says 'form1 is not defined'???!!!! I have written this if condition about 20 different ways and it usually runs on IE and Chrome but not FF, getting flustered with it. Oh and if I remove the if clause it will show the alert box on FF, so the problem lies in the If statement. Why would this cause errors with FF? Thanks :bigsmile:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>

<script type="text/javascript">
function show_alert()
{
	if (form1.CheckboxGroup1_0.checked == true)
    alert("I am an alert box!")
}
</script>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test Page</title>
</head>

<body>
    <form id="form1" name="form1" method="post" action="">
      <p>
        <label>
          <input type="checkbox" name="CheckboxGroup1" value="blue" id="CheckboxGroup1_0" />
          Blue</label>

         <br />

        <label>
          <input type="checkbox" name="CheckboxGroup1" value="yellow" id="CheckboxGroup1_1" />
          Yellow</label>

             <br />

        <label>
          <input type="checkbox" name="CheckboxGroup1" value="black" id="CheckboxGroup1_2" />
          Black</label>
      </p>

      <p>
          <input type="button" onclick="show_alert()" value="Submit" />
      </p>
    </form>
</body>
</html>


This post has been edited by jimdandy75: 02 September 2010 - 12:57 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Simple Script runs on IE and Chrome but not FF

#2 jimdandy75  Icon User is offline

  • D.I.C Regular

Reputation: 37
  • View blog
  • Posts: 311
  • Joined: 30-June 08

Re: Simple Script runs on IE and Chrome but not FF

Posted 02 September 2010 - 02:10 PM

I got it :blush:

<script type="text/javascript">
function show_alert()
{
    if (document.form1.CheckboxGroup1_0.checked == true)
    alert("I am an alert box!")
}
</script>

Was This Post Helpful? 0
  • +
  • -

#3 gregwhitworth  Icon User is offline

  • Tired.
  • member icon

Reputation: 219
  • View blog
  • Posts: 1,605
  • Joined: 20-January 09

Re: Simple Script runs on IE and Chrome but not FF

Posted 02 September 2010 - 05:06 PM

Good job. Way to keep working at it even after you post to DIC. :clap:

--

Greg
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1