Error using innerHtml in Mozilla

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prasath03
    New Member
    • Jun 2007
    • 30

    Error using innerHtml in Mozilla

    Hi,

    I developed one html page that contains one combo box for selectig mulltiple products to purchase with required quantity. I used innerHTML to add the textfield dynamically to enter the required number of quantity to selected products.

    The problem arises when i submit the form and try to get all corresponding values in another jsp page using request.getPara meterValues("va l") and request.getPara meter("sale") its working perfectly in Internet Explorer(IE) without any error, but when i tried to run the same files in Mozilla Firefox it showed java.lang.NullP ointerException .

    Herewith i also add the code for your consideration. What i made a mistake in those file,

    If anybody knows the solution let me know....

    I am using Mozilla, Internet Explorer and Apache Tomcat 4.1.3, OS: Windows


    Thanks in Advance,

    V. Prasath

    Html File:

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Order Brief</title>
    </head>
    <body>
    <SCRIPT language=javasc ript>
    function showSelection(i ndex)
    {
    //alert("In showSelection() ");
    // var selections=docu ment.search.IND EX_NAME.selecte d
    var selections="";

    for(var i=0;i<index.opt ions.length;i++ )
    {
    if(index.option s[i].selected)
    selections+="<d iv><table><tr>< td width='148' colspan='4' height='19' align='right'>< font color='red' face='verdana' size='2'>"+inde x.options[i].text+":</td><td width='359' height='19'>&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;<input type='text' name='val' size=5><br></td></tr></table></div>";
    }

    if( selections.leng th !=0)
    {
    selections=sele ctions.substrin g(0,selections. length-1);
    }

    document.getEle mentById("selec tedIndexes").in nerHTML=selecti ons;

    // alert("Selectio ns :"+selection s);
    }
    </SCRIPT>
    <table bgcolor="white" >

    <form name="test" method="post" action="test.js p">

    <tr>
    <td width="335" colspan="3" height="19"><b> <font face="Verdana" size="2">
    <span style="backgrou nd-color: #FFE680">&nbsp; Select Products :</span></font></b></td>
    <td width="8" height="19">&nb sp;</td>
    <td width="12" height="19">&nb sp;</td>
    <td width="148" colspan="4" height="19"><b> <font face="Verdana" size="2">Name of Products</font></b></td>
    <td width="359" height="19"><b> <font face="Verdana" size="2">&nbsp; Quantity</font></b></td>
    </tr>
    <tr>
    <td width="335" colspan="3" rowspan="3" height="59">
    <p align="center">
    <SELECT onchange=showSe lection(this) multiple size=4 name=INDEX_NAME style="font-family: Verdana; font-size: 10pt; font-weight: bold">
    <OPTION value=CAP>
    Spirovit SP-1<OPTION value=TOIA>PC Spirometry<OPTI ON value=TOIBG>
    Cardioplus<OPTI ON value=TOIKM>Vis tron CT<OPTION value=TOIPU>
    Mark V Provis<OPTION value=TOIL>BP-102 plus<OPTION value=TOIH>
    Maglife C Plus</SELECT></td>
    <td width="8" height="19">&nb sp;</td>
    <td width="12" height="57" rowspan="3">&nb sp;</td>
    <td width="507" colspan="5" rowspan="3" height="59"><SP AN id=selectedInde xes></span></td>
    </tr>

    <tr>
    <td >
    &nbsp;

    </td>
    </tr><tr>
    <td >
    &nbsp;

    </td>
    </tr><tr>
    <td width="862" colspan="10" height="19" valign="top"><b >
    <font size="1" face="Verdana">
    <font color="#FF0000" >&nbsp;&nbsp;&n bsp; Press <span class="td_greyB old">
    Ctrl key</span> to select multiple products</font></font></b><font color="#FF0000" >.</font></td>
    </tr>
    <tr>
    <td width="187" height="22">
    <p align="right">< font face="Verdana" size="2"><b>Sal es Person :</b></font></td>
    <td width="5" height="22"></td>
    <td width="144" height="22">

    <b><font face="Verdana">

    <input type="text" name="sale" size="20"></font></b></td>
    <td width="8" height="22">&nb sp;</td>
    <td width="12" height="22">&nb sp;</td>
    <td width="135" height="22">
    </tr>
    <tr>
    <td >&nbsp;&nbsp;&n bsp;&nbsp;&nbsp ;&nbsp;&nbsp;&n bsp;
    &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;&nbsp;
    &nbsp;&nbsp;&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;
    <input type="submit" value="Save" name="B1">

    </td>
    </tr></form>
    </body>
    </html>



    Jsp File:

    <%@ page language="java" contentType="te xt/html" %>
    <% String get_values[];
    get_values=requ est.getParamete rValues("val");
    for(int i=0;i<get_value s.length;i++)
    {
    out.println("Qt y = "+get_value s[i]);
    }
    out.println("Sa les = "+request.getPa rameter("sale") );

    %>
  • Dököll
    Recognized Expert Top Contributor
    • Nov 2006
    • 2379

    #2
    Hello, prasath03!

    Do you have Mozilla and IE running on the same machine you are running your program?

    If you are using two different systems and copying files over to try on other workstations, you may have issues. In which case you may have to build the app from the system you're running it.

    Please stay tuned for a more accurate answer, prasath03... I found copying files over to other machines do not usally carry over the proper settings that would allow files to load normally.

    In a bit, and sorry for your troubles!

    Dököll

    Comment

    • prasath03
      New Member
      • Jun 2007
      • 30

      #3
      Originally posted by Dököll
      Hello, prasath03!

      Do you have Mozilla and IE running on the same machine you are running your program?

      If you are using two different systems and copying files over to try on other workstations, you may have issues. In which case you may have to build the app from the system you're running it.

      Please stay tuned for a more accurate answer, prasath03... I found copying files over to other machines do not usally carry over the proper settings that would allow files to load normally.

      In a bit, and sorry for your troubles!

      Dököll
      thanks for your reply,

      Yes, i have both browser in the same machine...
      but even if i tried this program over the network in Mozilla again it shows me the same error(NullPoint erException)..

      what i have to do about this issue?

      Thanks in Advance

      Comment

      • r035198x
        MVP
        • Sep 2006
        • 13225

        #4
        Originally posted by prasath03
        thanks for your reply,

        Yes, i have both browser in the same machine...
        but even if i tried this program over the network in Mozilla again it shows me the same error(NullPoint erException)..

        what i have to do about this issue?

        Thanks in Advance
        Where did you create the select called "val"?

        Comment

        • prasath03
          New Member
          • Jun 2007
          • 30

          #5
          Originally posted by r035198x
          Where did you create the select called "val"?
          i created the "val" in javascripti function whenever i select the product it will create one textbox with their product name.
          here the function:

          for(var i=0;i<index.opt ions.length;i++ )
          {
          if(index.option s[i].selected)
          selections+="<t able><tr><td width='148' colspan='4' height='19' align='right'>< font color='red' face='verdana' size='2'>"+inde x.options[i].text+":</td><td width='359' height='19'>&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;<input type='text' name='val' size=5><br></td></tr></table>";
          }

          Comment

          • r035198x
            MVP
            • Sep 2006
            • 13225

            #6
            Originally posted by prasath03
            i created the "val" in javascripti function whenever i select the product it will create one textbox with their product name.
            here the function:

            for(var i=0;i<index.opt ions.length;i++ )
            {
            if(index.option s[i].selected)
            selections+="<t able><tr><td width='148' colspan='4' height='19' align='right'>< font color='red' face='verdana' size='2'>"+inde x.options[i].text+":</td><td width='359' height='19'>&nb sp;&nbsp;&nbsp; &nbsp;&nbsp;&nb sp;<input type='text' name='val' size=5><br></td></tr></table>";
            }
            If it's a textbox then you should use getParameter instead of getParameterVal ues.

            Comment

            • drhowarddrfine
              Recognized Expert Expert
              • Sep 2006
              • 7434

              #7
              A few problems I question.
              1) You declare HTML yet use some XHTML end tags. In some cases, a browser stops parsing at that point.
              2) Since some of your markup is invalid, particularly the form is misplaced, I'm wondering if this is messing up the DOM. Modern browsers like Firefox are more likely to follow the DOM properly than any version of IE. So validate and fix your errors there.

              Comment

              Working...