Fork me on GitHub

Broken Browser due to what???  Bottom

  • Ok all I have gone round and round with everything I can think of to debug this JS inside PN and can't figure out what in the heck is wrong, so I wanted to see if anyone here may have a better set of eyes than myself and might be able to poitn out to me what in the heck I am missing and what causes this scipt to not function inside PN when a user is using IE5 or higher ( please keep in mind I am NO JavaScript guy and this is not my script.


    This is the JS I have that I found here Usable Forms

    Actual JavaScript:

    Code

    /*****************************************/
    /** Usable Forms 1.0, May 2003          **/
    /** Written by ppk, www.quirksmode.org  **/
    /** Instructions for use on my site     **/
    /**                                     **/
    /** You may use or change this script   **/
    /** only when this copyright notice     **/
    /** is intact.                          **/
    /**                                     **/
    /** If you extend the script, please    **/
    /** add a short description and your    **/
    /** name below.                         **/
    /*****************************************/


    var relatedTag = 'TR';

    var compatible = (
        document.getElementById && document.getElementsByTagName && document.createElement
        &&
        !(navigator.userAgent.indexOf('MSIE 5') != -1 && navigator.userAgent.indexOf('Mac') != -1)
        );

    if (compatible)
        document.write('<style>.accessibility{display: none}</style>');


    function prepareForm()
    {
        if (!compatible) return;
        var marker = document.createElement(relatedTag);
        marker.style.display = 'none';

        var x = document.getElementsByTagName(relatedTag);
        var toBeRemoved = new array;
        for (var i=0;i<x.length;i++)
        {
            if (x[i].getAttribute('relation'))
            {
                var y = getAllFormFields(x[i]);
                x[i].nestedRels = new array;
                for (var j=0;j<y.length;j++)
                {
                    var rel = y[j].getAttribute('show');
                    if (!rel || rel == 'none') continue;
                    x[i].nestedRels.push(rel);
                }
                if (!x[i].nestedRels.length) x[i].nestedRels = null;
                toBeRemoved.push(x[i]);
            }
        }

        while (toBeRemoved.length)
        {
            var rel = toBeRemoved[0].getAttribute('relation');
            if (!document.getElementById(rel))
            {
                var newMarker = marker.cloneNode(true);
                newMarker.id = rel;
                toBeRemoved[0].parentNode.replaceChild(newMarker,toBeRemoved[0]);
            }
            document.getElementById('waitingRoom').appendChild(toBeRemoved.shift());
        }
        document.onclick = arrangeFormFields;

        var y = document.getElementsByTagName('input');
        for (var i=0;i<y.length;i++)
        {
            if (y[i].checked && y[i].getAttribute('show'))
                intoMainForm(y[i].getAttribute('show'))
        }

        var z = document.getElementsByTagName('select');
       
        // Opera weird with hidden selects in quirks mode: selectedIndex = -1
       
        for (var i=0;i<z.length;i++)
        {
            if (z[i].options[z[i].selectedIndex].getAttribute('show'))
            {
                z[i].onchange = arrangeFormFields;
                intoMainForm(z[i].options[z[i].selectedIndex].getAttribute('show'))
            }          
        }
    }

    function arrangeFormFields(e)
    {
        if (!e) var e = window.event;
        var tg = (e.target) ? e.target : e.srcElement;
        if (
            !(tg.nodeName == 'SELECT' && e.type == 'change')
            &&
            !(tg.nodeName == 'INPUT' && tg.getAttribute('show'))
           ) return;
        var toBeInserted = tg.getAttribute('show');

        /* Why no switch statement? Because Netscape 3 gives an error message on encountering it,
            and this script must degrade perfectly. */


        if (tg.type == 'checkbox')
        {
            if (tg.checked)
                intoMainForm(toBeInserted);
            else
                intoWaitingRoom(toBeInserted);
        }
        else if (tg.type == 'radio')
        {
            removeOthers(tg.form[tg.name],toBeInserted)
            intoMainForm(toBeInserted);
        }
        else if (tg.type == 'select-one')
        {
            toBeInserted = tg.options[tg.selectedIndex].getAttribute('show');
            removeOthers(tg.options,toBeInserted);
            intoMainForm(toBeInserted);
        }
    }

    function removeOthers(others,toBeInserted)
    {
        var toBeRemoved = new array;
        for (var i=0;i<others.length;i++)
        {
            var show = others[i].getAttribute('show');
            if (show != toBeInserted)
                toBeRemoved.push(show);
        }
        while (toBeRemoved.length)
            intoWaitingRoom(toBeRemoved.shift());
    }

    function gatherElements(name)
    {
        var Elements = new array;
        var x = document.getElementsByTagName(relatedTag);
        for (var i=0;i<x.length;i++)
            if (x[i].getAttribute('relation') == name)
                Elements.push(x[i]);
        return Elements;
    }

    function intoWaitingRoom(name)
    {
        if (name == 'none') return;
        var Elements = gatherElements(name);
        if (isInWaitingRoom(Elements[0])) return;
        while (Elements.length)
        {
            if (Elements[0].nestedRels)
                for (var i=0;i<Elements[0].nestedRels.length;i++)
                    intoWaitingRoom(Elements[0].nestedRels[i]);
            document.getElementById('waitingRoom').appendChild(Elements.shift())
        }
    }

    function intoMainForm(name)
    {
        if (name == 'none') return;
        var Elements = gatherElements(name);
        if (!isInWaitingRoom(Elements[0])) return;
        var insertPoint = document.getElementById(name);
        while (Elements.length)
            insertPoint.parentNode.insertBefore(Elements.shift(),insertPoint)
    }

    function isInWaitingRoom(obj)
    {
        while(obj.nodeName != 'BODY')
        {
            obj=obj.parentNode;
            if (obj.id == 'waitingRoom')
                return true;
        }
        return false;
    }


    function getAllFormFields(node)
    {
        var allFormFields = new array;
        var x = node.getElementsByTagName('input');
        for (var i=0;i<x.length;i++)
            allFormFields.push(x[i]);
        var y = node.getElementsByTagName('option');
        for (var i=0;i<y.length;i++)
            allFormFields.push(y[i]);
        return allFormFields;
    }

    // push and shift for IE5

    function array_push() {
        var A_p = 0
        for (A_p = 0; A_p < arguments.length; A_p++) {
            this[this.length] = arguments[A_p]
        }
        return this.length
    }

    if (typeof array.prototype.push == "undefined") {
        array.prototype.push = array_push
    }

    function array_shift() {
        var A_s = 0
        var response = this[0]
        for (A_s = 0; A_s < this.length-1; A_s++) {
            this[A_s] = this[A_s + 1]
        }
        this.length--
        return response
    }

    if (typeof array.prototype.shift == "undefined") {
        array.prototype.shift = array_shift
    }


    Actual pntemplate used in PN:

    Code

    <!--[include file="pnChange_admin_menu.htm"]-->
    <br /><br />
    <div class="pn-title"><!--[pnml name="_pnChangeADD"]--></div><br /><br />
    <!--[pnChangeadditionalheaders nameOfFile="usableforms.js" typeOfFile="javascript"]-->
    <body onLoad="prepareForm()">

    <form name="formPicker" action="<!--[pnmodurl modname="pnChange" func="create"]-->" method="post" enctype="application/x-www-form-urlencoded">



    <div>
        <input type="hidden" name="authid" value="<!--[pnsecgenauthkey module="pnChange"]-->" />
        <table border="0" cellpadding="2" cellspacing="1"><tbody>
        <input type="hidden" name="stepCount" value="0"/>
        <input type="hidden" name="descCount" value="0"/>

          <tr>
            <td class="question">Select Change Type</td>
            <td>
              <select name="CM_type">
                 <option show="none">Select</option>
                 <option show="network" value="network_cm">Network</option>
                 <option show="server" value="server_cm">Server</option>
              </select>
            </td>
          </tr>

          <tr relation="network">
              <td>Change Requestor<br /><input name="requestor" value="<!--[$name|pnvarprepfordisplay]-->"><br /><br /></td>
              <td>Requestors Email<br /><input name="rEmail"    value="<!--[$email|pnvarprepfordisplay]-->"><br /><br /></td>
          </tr>
          <tr relation="network">
                 <td>Phone Number<br /><input name="phone"><br /><br /></td>
                 <td>Cell/Pager<br /><input name="cellP"><br /><br /></td>
          </tr>

          <tr relation="network">
              <td>Change Performed by<br /><input name="performed"><br /><br /></td>
              <td>Email<br /><input="perfmail"><br /><br /></td>
          </tr>

          <tr relation="network">
                 <td>Change Management Title<br /><input name="cm_name"><br /><br /></td>
          </tr>

          <tr id="network" style="display: none;"></tr>

          <tr relation="server">
            <td class="question"><span class="accessibility">Server Change Details:</span>Server Change detail.</td>
            <td><textarea name="server_detail"></textarea></td>
          </tr>

          <tr id="server" style="display: none;"></tr>


      <input type="submit" value="Send form" />
         </table>

         <table><tbody id="waitingRoom"
          style="display: none"></tbody></table>
    </div>
    </form>



    Please if anyone here can help me out I will forever be in your debt.


    Thanks a million
    -SUNADMN
  • No bites on this one yet???



    -SUNADMN
  • you'll rarely get a 'bite' when the code example is that long. nobody can debug all the code you have. If you can isolate the examples to JUST the problem areas, you'll get more help (not from me, I don't know JS, but from others).
  • Sounds like we don't have any JS programmers here, but you might find some here. Wish I could be more help!

This list is based on users active over the last 60 minutes.