Hello everyone,

I have a button on a page that is created with the <input> statement - this statement also contains the event handler onClick. The button displays correctly on the page but the event handler is not working - I know this as I put a simple alert at the beginning of the function PrcsBtn1. I am very new to all of this - what have I missed?

<script type="text/javascript" language="javascript">
         function PrcsBtn1()
           {
             var data2 = new Array();
             data2[0] = "Cancel Appointment";

             var packedS="";
             for (i = 0; (i < data2.length); i++)
                {
                   if (i > 0)
                      {
                        packedS += ",";
                      }
                   packedS += escape(data2[i]);
                }

                window.location = "mypage11 new.html?"+packedS;
                window.open = "mypage11 new.html?"+packedS;
           }
    </script>

    <input name="b1" type="button" value="CANCEL APPOINTMENT" document.apptcalendar.b1.onClick="javascript:PrcsBtn1();">

Get rid of the the extra stuff befor the event attribute. So it should look like this:

<input name="b1" type="button" value="CANCEL APPOINTMENT" document.apptcalendar.b1.onClick="javascript:PrcsBtn1();">

You also don't need the "javascript:"

So this is what it turns to:

<input name="b1" type="button" value="CANCEL APPOINTMENT" onClick="PrcsBtn1();">

Wow! Thanks loads...I think I'm finally catching on to this JavaScript stuff - not bad for an old mainframe programmer. Again, many, many thanks.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.