www.webdeveloper.com
Results 1 to 4 of 4

Thread: this code works on one computer but not another

Hybrid View

  1. #1
    Join Date
    Mar 2006
    Posts
    148

    this code works on one computer but not another

    Hey the code below worked on my new computer using IE 9, but when I test it out on another computer it doesn't work on IE 7 any thoughts? For some reason the code below is not gathering the elements with the tag name q and putting it into an array.

    var q = document.getElementsByName("q")



    <HTML>
    <HEAD>
    <TITLE>Send Email</TITLE>


    <script type="text/javascript">

    //tags that are named q are questions
    //tags that are named numbers are answer


    function sendmail()
    {

    var mailmessage = ""
    var errormessage = ""

    var x = document.getElementById("feedbackform")
    var q = document.getElementsByName("q")
    var e = document.getElementsByName("e")

    var fcompleted = true
    var qanswered

    for (i=0; i<q.length; i++)
    {

    mailmessage += q[i].innerHTML + "\t";
    e[i].style.display = "none";

    }

    mailmessage += "\n"
    alert (fcompleted)

    for (i=0; i<q.length; i++)
    {

    a = document.getElementsByName(i)
    if(a[0].type == "radio")
    {

    qanswered = false

    for(ii=0; ii<a.length; ii++)
    {

    if(a[ii].checked)
    {
    mailmessage += a[ii].value + "\t"
    qanswered = true

    }
    if(qanswered == false)
    {
    e[i].style.display = "inline"
    fcompleted = false
    errormessage += q[i].innerHTML + "\n"
    }

    }
    }
    else if(a[0].type == "text")
    {

    if(a[0].value == "")
    {
    fcompleted = false
    }
    else
    {
    mailmessage += a[0].value + "\t"
    }

    }
    //else if(a[0]


    else
    {
    mailmessage += a[0].value + "\t"
    }

    }

    if(fcompleted == true)
    {
    alert("survey sent")
    }
    else
    {
    alert("You still need to answer the following: \n" + errormessage)
    }

    document.frmsendmail.p_messege.value = mailmessage

    document.frmsendmail.p_subject.value = "New Hire Training Survey for" + x.elements[0].value + " " + x.elements[1].value
    document.frmsendmail.submit()
    document.getElementById("form_stamp").innerHTML = "Last successful tracking email sent: " + Date() + "<br>" + document.getElementById("form_stamp").innerHTML

    }

    </script>


    </HEAD>
    <BODY>


    <form id="feedbackform">

    <table>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">Date of Hire:</td><td><input type="text" name=0></td><td></td>
    <td width="10"><div name="e">*</div></td><td name="q">Trainer:</td><td width="10"></td>


    <td>

    <select name=1>

    <option value="Derek Laur">Derek Laur</option>

    </select>

    </td>


    <td></td>


    <td width="10"><div name="e">*</div></td><td><td name="q">CCC: </td>
    <td>

    <select name=2>
    <option value="Austin">Austin</option>

    </select>

    </td>
    </tr>

    </tr>

    </table>


    <br/>


    <table width="790">

    <tr class="title">
    <th width="10"></th><th>Trainer</th> <th colspan="5"></th>
    </tr>


    <tr class="sectionheader">
    <td width="10"></td><td width="380"></td> <th width="80">Stongly Agree</th> <th width="80">Agree</th> <th width="80">Undecided</th> <th width="80">Disagree</th> <th width="80">Strongly Disagree</th>
    </tr>


    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">My Training leader was professional</td> <th><input type="radio" name=3 value="Strongly Agree"/></td> <th><input type="radio" name=3 value="Agree"/></td> <th><input type="radio" name=3 value="Undecided"/></td> <th><input type="radio" name=3 value="Disagree"/></td> <th><input type="radio" name=3 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">My Training leader treated everyone with respect</td> <th><input type="radio" name=4 value="Strongly Agree"/></td> <th><input type="radio" name=4 value="Agree"/></td> <th><input type="radio" name=4 value="Undecided"/></td> <th><input type="radio" name=4 value="Disagree"/></td> <th><input type="radio" name=4 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">My Training leader created an engaging environment(Gen Res/SPG): </td> <th><input type="radio" name=5 value="Strongly Agree"/></td> <th><input type="radio" name=5 value="Agree"/></td> <th><input type="radio" name=5 value="Undecided"/></td> <th><input type="radio" name=5 value="Disagree"/></td> <th><input type="radio" name=5 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><td>Comments:</td> <td colspan="5"></td>
    </tr>
    <tr>
    <td width="10"><div name="e">*</div></td><td name="q" colspan="6">Please enter your comments about the trainer below:</td>
    </tr>

    <tr>
    <td width="10"></td><td colspan="6"><textarea rows="5" cols="93" name=6></textarea></td>
    </tr>

    </table>


    <br/>


    <table>

    <tr>
    <td width="10"><td>Tools</td> <td></td>
    </tr>

    <tr class="sectionheader">
    <td width="10"></td><td></td> <th width="100">Stongly Agree</th> <th width="125">Agree</th> <th width="125">Undecided</th> <th width="125">Disagree</th> <th width="125">Strongly Disagree</th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">I was able to properly set up my systems when I arrived home</td> <th><input type="radio" name=7 value="Strongly Agree"/></th> <th><input type="radio" name=7 value="Agree"/></td> <th><input type="radio" name=7 value="Undecided"/></td> <th><input type="radio" name=7 value="Disagree"/></td> <th><input type="radio" name=7 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">My training prepared me to successfully navigate Saratoga</td> <th><input type="radio" name=8 value="Strongly Agree"/></td> <th><input type="radio" name=8 value="Agree"/></td> <th><input type="radio" name=8 value="Undecided"/></td> <th><input type="radio" name=8 value="Disagree"/></td> <th><input type="radio" name=8 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">I am familiar with all the tools and resources available to me</td> <th><input type="radio" name=9 value="Strongly Agree"/></td> <th><input type="radio" name=9 value="Agree"/></td> <th><input type="radio" name=9 value="Undecided"/></td> <th><input type="radio" name=9 value="Disagree"/></td> <th><input type="radio" name=9 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">I was provided with all the tools necessary to do my job</td> <th><input type="radio" name=10 value="Strongly Agree"/></td> <th><input type="radio" name=10 value="Agree"/></td> <th><input type="radio" name=10 value="Undecided"/></td> <th><input type="radio" name=10 value="Disagree"/></td> <th><input type="radio" name=10 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">My training prepared me to successfully interact with our guests </td> <th><input type="radio" name=11 value="Strongly Agree"/></td> <th><input type="radio" name=11 value="Agree"/></td> <th><input type="radio" name=11 value="Undecided"/></td> <th><input type="radio" name=11 value="Disagree"/></td> <th><input type="radio" name=11 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td></td><td>Comments:</td> <td></td>
    </tr>
    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">Please enter your comments about below:</td> <td></td>
    </tr>

    <tr>
    <td width="10"></td><td><textarea rows="5" cols="60" name=12></textarea></td> <td></td>
    </tr>

    </table>


    <br/>


    <table>

    <tr>
    <td width="10"></td><td>Environment</td> <td></td>
    </tr>

    <tr class="sectionheader">
    <td width="10"></td><td></td> <th width="100">Stongly Agree</th> <th width="125">Agree</th> <th width="125">Undecided</th> <th width="125">Disagree</th> <th width="125">Strongly Disagree</th>
    </tr>

    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">The environment helped me focus on learning</td> <th><input type="radio" name=13 value="Strongly Agree"/></td> <th><input type="radio" name=13 value="Agree"/></td> <th><input type="radio" name=13 value="Undecided"/></td> <th><input type="radio" name=13 value="Disagree"/></td> <th><input type="radio" name=13 value="Strongly Disagree"/></th>
    </tr>

    <tr>
    <td width="10"></td><td>Comments:</td> <td></td>
    </tr>
    <tr>
    <td width="10"><div name="e">*</div></td><td name="q">Please enter your comments about the training environment below:</td> <td></td>
    </tr>

    <tr>
    <td width="10"></td><td><textarea rows="5" cols="60" name=14></textarea></td> <td></td>
    </tr>

    </table>

    </form>

    </div>

    <input type="button" value="click here to submit" onClick="sendmail()">

    <FORM ACTION="USER_MANAGEMENT.USER_MNG_SENDMAIL.SUBMIT_FORM?p_uid=test" Method="POST" Name=frmsendmail target="email_confirm">

    </form>



    <iframe name="email_confirm" style="display:none;"></iframe>

    </BODY>
    </HTML>

  2. #2
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Your code needs to be re-done completely for several reasons.

    The name attribute is deprecated except for use on the elements of forms. When a common name is applied to a group of form elements, they form an addressable array, which means that document.getElementsByName is effectively redundant.

    One way to address a group of elements would be to give each a unique ID with a sequential numerical suffix, starting at say 1:

    Code:
    for( var i = 1, elem; ( elem = document.getElementById( "myElemId" + i ) ); i++ )
    {
      /* do something to elem */
    }

    Also note that identifiers must not begin with a digit.


    You have an indicated error on this line, due to a non-existent element:
    Code:
    document.frmsendmail.p_messege.value = mailmessage

  3. #3
    Join Date
    Mar 2006
    Posts
    148
    can you explain how that for loops works?

  4. #4
    Join Date
    Mar 2007
    Location
    U.K.
    Posts
    1,127
    Quote Originally Posted by domiereavron View Post
    can you explain how that for loops works?

    It starts by trying to get a reference to an element with ID "myElemId1". If it succeeds it acts on that element.
    Then it tries to get "myElemId2" and so on until it fails.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles