CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 6 of 6
  1. #1
    Join Date
    Jun 2008
    Posts
    142

    Getting Javascript error when i open popup.

    Hi,

    I am getting javascript error when i try to open a small calendar popup window. I have one calender text field. beside that text field calendar icon is there. when i click on that icon it's not open the small calendar popup. it is showing the following error in firebug console i.e " document.updateContact.birthYear is undefined"

    i wrote the following code in java class.
    Code:
     if ( k.equals("BIRTHDAY") )
        {
          String birthDay = "", birthYear = "";
          if ( psn != null && psn.getBirthDate() != null )
          {
            String birthDateYear = psn.getBirthDate().trim();
            if ( birthDateYear != null && birthDateYear.length() == 10 )  // MM.DD.YYYY
            {
              birthYear = birthDateYear.substring(6);
              birthDay  = birthDateYear.substring(0,5);
            }
            else if ( birthDateYear != null && birthDateYear.length() == 11 )  // MON.DD.YYYY
            {
              birthYear = birthDateYear.substring(7);
              birthDay  = birthDateYear.substring(0,6);
            }
            else if ( birthDateYear != null && birthDateYear.length() == 6 )  // MON.DD
            {
              birthDay  = birthDateYear;
            }
            else if ( birthDateYear != null && birthDateYear.length() == 5 )  // .YYYY, or 07.20
            {
              if ( birthDateYear.startsWith(".") )        birthYear  = birthDateYear.substring(1);
              else                                        birthDay   = birthDateYear;
            }
          }
    
          buf.append( "<input type=text class=\""+className+"\" name=birthDay size=6 value=\""+birthDay+"\">" );
          buf.append( " <img onMouseUp=\"javascript:opencalBD(document."+formName+".birthYear.value+'.'+document."+formName+".birthDay.value);\" src=\"graphics/ozicon18cal.gif\" align=absmiddle>" );
          buf.append( " ,  <input type=text class=\""+className+"\" name=birthYear size=4 value=\""+birthYear+"\">" );
          buf.append( " <span class=calDayFmtGreen>(MON.DD,YYYY)</span>" );
          buf.append( "<input type=hidden name=__BIRTHDAY value=Y>" );
          return buf.toString();
        }
    can any body give an idea on this ??

    Thanks in advance..

  2. #2
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting Javascript error when i open popup.

    There are two reasons why you could be getting that error.

    • The element you are attempting to reference doesn't exist.
    • The element has not yet been created at the time of reference to it.

    I would guess that your problem is the second.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  3. #3
    Join Date
    Jun 2008
    Posts
    142

    Re: Getting Javascript error when i open popup.

    these are the elements which already there. right ??

    Code:
      buf.append( "<input type=text class=\""+className+"\" name=birthDay size=6 value=\""+birthDay+"\">" );
          buf.append( " <img onMouseUp=\"javascript:opencalBD(document."+formName+".birthYear.value+'.'+document."+formName+".birthDay.value);\" src=\"graphics/ozicon18cal.gif\" align=absmiddle>" );
          buf.append( " ,  <input type=text class=\""+className+"\" name=birthYear size=4 value=\""+birthYear+"\">" );
    in the above 3 lines code, 2nd line is giving error. birthYear is undefined.

    thanks

  4. #4
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting Javascript error when i open popup.

    But, from the snippet of code that you have posted, there is no way for us to know if that append and then the returned text was ever truly appended to the actual form or HTML contents.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

  5. #5
    Join Date
    Jun 2008
    Posts
    142

    Re: Getting Javascript error when i open popup.

    this is the form

    Code:
    <form name=updateContact action="ozSlsContactPdt.jsp" method=post>
    <TABLE width=98% cellspacing=0 cellpadding=0 border=0 align=center>
    <TR>
    <TD width="50%" align=center valign=top><table width=100% cellspacing=0 cellpadding=0 border=0>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Job Title</font>: &nbsp;</td>
            <td class=formInput><input type=text name=JOBTITLE class="textInput" value="" size=32 ><input type=hidden name=__JOBTITLE value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Office</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name="CF_21" value="" size=30 ><input type=hidden name=CF_21_id value=""><input type=hidden name=__CF_21 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Assistant&#39;s Name</font>: &nbsp;</td>
    
            <td class=formInput><input type=text class="textInput" name="CF_30" value="" size=30 ><input type=hidden name=CF_30_id value=""><input type=hidden name=__CF_30 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Assistant&#39;s Phone</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name="CF_34" value="" size=30 ><input type=hidden name=CF_34_id value=""><input type=hidden name=__CF_34 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Manager&#39;s Name</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name="CF_8" value="" size=30 ><input type=hidden name=CF_8_id value=""><input type=hidden name=__CF_8 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Manager&#39;s Phone</font>: &nbsp;</td>
    
            <td class=formInput><input type=text class="textInput" name="CF_1" value="" size=30 ><input type=hidden name=CF_1_id value=""><input type=hidden name=__CF_1 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Contact Summary</font>: &nbsp;</td>
            <td class=formInput><textarea class="textInput" name="CF_35"  rows=3 cols=36 ></textarea><input type=hidden name=CF_35_id value=""><input type=hidden name=__CF_35 value=Y></td>
          </tr>
    </table></TD>
    
    <TD width="50%" align=center valign=top><table width=100% cellspacing=0 cellpadding=0 border=0>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Nickname</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name="CF_32" value="" size=30 ><input type=hidden name=CF_32_id value=""><input type=hidden name=__CF_32 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Title</font>: &nbsp;</td>
    
            <td class=formInput><select name=TITLE class=selInput><option value=""><option value="DOC"> Dr.<option value="MISS"> Miss<option value="MR"> Mr.<option value="MRS"> Mrs.<option value="MS"> Ms.<option value="PROF"> Prof.</select><input type=hidden name=__TITLE value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Suffix</font>: &nbsp;</td>
            <td class=formInput><select class=selInput name="CF_28"><option value=""> <option value="I" > I<option value="II" > II<option value="III" > III<option value="Jr." > Jr.<option value="Sr." > Sr.</select><input type=hidden name=CF_28_id value=""><input type=hidden name=__CF_28 value=Y></td>
    
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Birthday</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name=birthDay size=6 value=""> <img onMouseDown="javascript:opencalBD(document.updateContact.birthYear.value+'.'+document.updateContact.birthDay.value);" src="graphics/ozicon18cal.gif" align=absmiddle> ,  <input type=text class="textInput" name=birthYear size=4 value=""> <span class=calDayFmtGreen>(MON.DD,YYYY)</span><input type=hidden name=__BIRTHDAY value=Y></td>
          </tr>
      // here i am getting error.
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Anniversary</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name="CF_29" id="updateContact_CF_29"  value="" size=16 ><img onMouseUp="javascript:openCalV3('updateContact_CF_29');" src="graphics/ozicon18cal.gif" align=absmiddle><input type=hidden name=CF_29_id value=""><input type=hidden name=__CF_29 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Spouse&#39;s Name</font>: &nbsp;</td>
    
            <td class=formInput><input type=text class="textInput" name="CF_13" value="" size=30 ><input type=hidden name=CF_13_id value=""><input type=hidden name=__CF_13 value=Y></td>
          </tr>
    
          <tr>
            <td class=formPrompt><font style="font-family: Arial, Helvetica, sans-serif; font-size: 9pt; " >Follow Up</font>: &nbsp;</td>
            <td class=formInput><input type=text class="textInput" name="CF_4" id="updateContact_CF_4"  value="" size=16 ><img onMouseUp="javascript:openCalV3('updateContact_CF_4');" src="graphics/ozicon18cal.gif" align=absmiddle><input type=hidden name=CF_4_id value=""><input type=hidden name=__CF_4 value=Y></td>
          </tr>
    </table></TD>
    
    </TR>
    <tr>
      <td colspan=1 align=left>
        <input type=hidden name=ahsFormAction value="updateContact" > <input type=submit name=updateBtn class=normalButton value="Update" > 
        <input type=hidden name=id value="57">
      </td>
      <td></form></td>
    </tr>
    thanks

  6. #6
    Join Date
    May 2002
    Posts
    10,943

    Re: Getting Javascript error when i open popup.

    The form itself isn't what matters. You need to make 100&#37; sure that the actual element is being added to the form before it is referenced.
    If the post was helpful...Rate it! Remember to use [code] or [php] tags.

Posting Permissions

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





Click Here to Expand Forum to Full Width

Featured