DOM Error in internet explorer

Discussion in 'Javascript' started by Srini, Aug 2, 2007.

  1. Srini

    Srini Guest

    Hi All,

    I need the following problem to be solved in internet explorer
    (working fine in firefox). Please copy the code and check it in the
    internet explorer.
    Please click the link addmore and try to submit the form. Then you can
    see the javascript error. I need to fix this problem, so please
    explain me in this regards.

    ---------------------------------------------------------------------------------------------------
    <html>
    <head>
    <title>removeChild() Example</title>
    <script type="text/javascript">
    function resetForm() {

    alert(document.getElementById('noFiles').value);
    document.getElementById('noFiles').value = '';
    document.getElementById('noFiles').value = 1;
    }
    function frmvalidate(type,id)
    {
    //alert(document.venueform.noFiles.value)
    var lastRow = document.venueform.noFiles.value;
    for(file_number=1;file_number<=lastRow;file_number++)
    {
    //alert(file_number);
    var file_element = eval("document.venueform.fileName_"+file_number
    +".value");
    alert(file_element);
    if(file_element != "" && file_element.indexOf(".jpg")== -1 &&
    file_element.indexOf(".JPG") == -1 && file_element.indexOf(".jpeg") ==
    -1 )
    {
    alert("Please upload JPEG images only");
    return false;
    }
    }
    }
    function addFileTab()
    {
    oTBody = document.getElementById("addFileVenueId");
    document.venueform.noFiles.value =
    parseInt(document.venueform.noFiles.value) + 1;
    var lastRow = document.venueform.noFiles.value

    //var hidden_value = lastRow ;
    //var lastRow = parseInt(lRow) - 1;

    if(lastRow <= 5 )
    {
    oTBody.insertRow(lastRow);
    // var file_name = "fileName"+lastRow;
    var oinput = document.createElement("input");
    oinput.setAttribute("type", "file");
    oinput.setAttribute("class", "textbox");
    oinput.setAttribute("size", "25");
    oinput.setAttribute("name", "fileName_"+lastRow);
    // oinput.setAttribute("id", file_name);
    oTBody.rows[lastRow].insertCell(0);
    oTBody.rows[lastRow].cells[0].align = "left";
    // oTBody.rows[lastRow].cells[0].setAttribute("class","litetd");
    oTBody.rows[lastRow].cells[0].className="darktd";
    oTBody.rows[lastRow].cells[0].setAttribute("colspan","2");
    oTBody.rows[lastRow].cells[0].appendChild(oinput);


    //document.venueform.noFiles.value =
    parseInt(document.venueform.noFiles.value) + 1;

    //alert(document.venueform.noFiles.value);
    //document.getElementById("noFiles").value = hidden_value;

    if(lastRow == 5)
    document.getElementById("add_row").style.visibility = "hidden";

    /*if(lastRow == 2)
    document.getElementById("delete_row").style.visibility = "visible";
    */

    }
    }
    </script>
    </head>
    <body onload='resetForm()'><form name=venueform>
    <table width='50%' border='0' align='center' id='addFileVenueId'
    cellspacing=1 cellpadding=0>
    <tr align='center' class='rowhead'>
    <th height='20' colspan='2' class='headrow'>Upload Photo upto
    nos</th>
    <td >
    <span id='add_row'>
    <a href='javascript:;' onclick='addFileTab()'>Add more</a></span>
    </td>
    </tr>
    <tr>
    <td colspan='2' align='left' class='darktd'>
    <input type='file' name='fileName_1' id='fileName1'
    class='textbox' size='25'>
    </td>
    </tr>
    <tr>
    <td>
    <input type='button' value='Add' class='button' onClick="return
    frmvalidate()">
    <input type='hidden' name='noFiles' value='1' id='noFiles'>
    </td>
    </tr>

    </table>
    </form>
    </body>
    </html>

    ---------------------------------------------------------------------------------------------------

    Thanks in Advance.

    Regards,
    Srinivasan M
     
    Srini, Aug 2, 2007
    #1
    1. Advertising

  2. Srini

    David Mark Guest

    On Aug 2, 10:51 am, Srini <> wrote:
    > Hi All,
    >
    > I need the following problem to be solved in internet explorer
    > (working fine in firefox). Please copy the code and check it in the
    > internet explorer.
    > Please click the link addmore and try to submit the form. Then you can
    > see the javascript error. I need to fix this problem, so please
    > explain me in this regards.
    >
    > ---------------------------------------------------------------------------­------------------------
    > <html>
    > <head>
    > <title>removeChild() Example</title>


    That's an odd title for this example.

    > <script type="text/javascript">
    > function resetForm() {
    >
    > alert(document.getElementById('noFiles').value);
    > document.getElementById('noFiles').value = '';
    > document.getElementById('noFiles').value = 1;}
    >
    > function frmvalidate(type,id)
    > {
    > //alert(document.venueform.noFiles.value)
    > var lastRow = document.venueform.noFiles.value;
    > for(file_number=1;file_number<=lastRow;file_number++)
    > {
    > //alert(file_number);
    > var file_element = eval("document.venueform.fileName_"+file_number
    > +".value");
    > alert(file_element);
    > if(file_element != "" && file_element.indexOf(".jpg")== -1 &&
    > file_element.indexOf(".JPG") == -1 && file_element.indexOf(".jpeg") ==
    > -1 )
    > {
    > alert("Please upload JPEG images only");
    > return false;
    > }
    > }}
    >
    > function addFileTab()
    > {
    > oTBody = document.getElementById("addFileVenueId");
    > document.venueform.noFiles.value =
    > parseInt(document.venueform.noFiles.value) + 1;
    > var lastRow = document.venueform.noFiles.value
    >
    > //var hidden_value = lastRow ;
    > //var lastRow = parseInt(lRow) - 1;
    >
    > if(lastRow <= 5 )
    > {
    > oTBody.insertRow(lastRow);
    > // var file_name = "fileName"+lastRow;
    > var oinput = document.createElement("input");
    > oinput.setAttribute("type", "file");
    > oinput.setAttribute("class", "textbox");
    > oinput.setAttribute("size", "25");
    > oinput.setAttribute("name", "fileName_"+lastRow);


    Here's the problem. This is a known IE bug. The name is set, but it
    doesn't update the elements collection. For a workaround, you can
    either iterate through the form elements and look for the name you
    need or set the ID and use getElementById.

    > // oinput.setAttribute("id",file_name);
    > oTBody.rows[lastRow].insertCell(0);
    > oTBody.rows[lastRow].cells[0].align = "left";
    > // oTBody.rows[lastRow].cells[0].setAttribute("class","litetd");
    > oTBody.rows[lastRow].cells[0].className="darktd";
    > oTBody.rows[lastRow].cells[0].setAttribute("colspan","2");
    > oTBody.rows[lastRow].cells[0].appendChild(oinput);
    >
    > //document.venueform.noFiles.value =
    > parseInt(document.venueform.noFiles.value) + 1;
    >
    > //alert(document.venueform.noFiles.value);
    > //document.getElementById("noFiles").value = hidden_value;
    >
    > if(lastRow == 5)
    > document.getElementById("add_row").style.visibility = "hidden";
    >
    > /*if(lastRow == 2)
    > document.getElementById("delete_row").style.visibility = "visible";
    > */
    >
    > }}
    >
    > </script>
    > </head>
    > <body onload='resetForm()'><form name=venueform>
    > <table width='50%' border='0' align='center' id='addFileVenueId'
    > cellspacing=1 cellpadding=0>
    > <tr align='center' class='rowhead'>
    > <th height='20' colspan='2' class='headrow'>Upload Photo upto
    > nos</th>
    > <td >
    > <span id='add_row'>
    > <a href='javascript:;' onclick='addFileTab()'>Add more</a></span>


    You should generate this link with script if there is no unscripted
    equivalent. In any event, don't use "javascript:;" for an href (or
    anything preceded by "javascript:" for that matter.)
     
    David Mark, Aug 2, 2007
    #2
    1. Advertising

  3. Srini

    Srini Guest

    Hi David Mark,

    Thank you very much for your valuable help in this regard.
    I won't forget this.

    Thanks,
    Srinivasan M
     
    Srini, Aug 4, 2007
    #3
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. cmay
    Replies:
    0
    Views:
    1,138
  2. kayodeok
    Replies:
    2
    Views:
    1,645
    kayodeok
    Feb 28, 2004
  3. Ed Hauptman
    Replies:
    7
    Views:
    1,025
    Ed Hauptman
    Aug 7, 2009
  4. Raghuram Banda
    Replies:
    3
    Views:
    110
  5. John Smith
    Replies:
    1
    Views:
    146
    Evertjan.
    Mar 12, 2005
Loading...

Share This Page