javascript function not working when script "language" attribute is changed to "type"

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • vikas251074
    New Member
    • Dec 2007
    • 198

    javascript function not working when script "language" attribute is changed to "type"

    When change the <script language="javas cript"> to <script type="text/javascript">, javascript function now works no more. Previously it was working. Javascript function is given below -
    Code:
    function log1()
    {
      window.location="log1.asp"
    }
    function page1()
    {
      window.location="page1.asp"
    }
    and place where calling this function are below -
    Code:
    <font style="position:absolute;left:300; top:400">
      <input type="button" style="width:100px" value="Login" onclick="log1()">
    </font> 
    <font style="position:absolute;left:300; top:450">
      <input type="button" style="width:100px" value="Back" onclick="page1()">
    </font>
    Where is the problem?

    Thanks and regards,
    Vikas
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    Try using window.location .href.

    Just a note: there's no need to use font tags. Replace them with div tags.

    Comment

    • vikas251074
      New Member
      • Dec 2007
      • 198

      #3
      I changed the code as follows -

      [CODE=javascript]function log1()
      {
      window.location .href="log1.asp "
      }

      [/CODE]Still it is not working.


      Should I not use <font> tag for placing text in browser? Is there any difference between <font> and <div> for placing text?

      Thanks and regards,
      Vikas
      Last edited by gits; Jun 5 '08, 11:47 AM. Reason: added code tags

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Show the rest of your code.
        Originally posted by vikas251074
        Should I not use <font> tag for placing text in browser? Is there any difference between <font> and <div> for placing text?
        The font tag is deprecated. You should use CSS for styling. Here you're not placing text within the font tags, you were just displaying buttons.

        Comment

        • vikas251074
          New Member
          • Dec 2007
          • 198

          #5
          This is my complete code.


          Code:
          <title>Material Entry Form</title>
          <!--#include file="Hdr.asp"-->
          <script type="text/javascript" src="calendarDateInput.js">
          </script>
          <script type="text/javascript">
          function checkpn(pn)
          {
            if (pn.value=="") 
            {
              pn.focus();
              alert("Persons name must be entered");
              return;
            }
            else if (!pn.value.match(/^[a-zA-Z .]*$/i))
            {
              pn.focus();
              alert("Special characters are not allowed.");
              return;
            }
            return;
          }
          function check_vech_no(vech_no)
          {
            if (vech_no.value=="") 
            {
              vech_no.focus();
              alert("Vehicle number must be entered");
              return;
            }
            else if (!vech_no.value.match(/^[a-zA-Z0-9 ()-/]*$/i)) 
            {
              vech_no.focus();
              alert("Special characters are not allowed.");
              return;
            }
            return;
          }
          function checkdrn(drn)
          {
            if (drn.value=="") 
            {
              drn.focus();
              alert("Driver name must be entered");
              return;
            }
            else if (!drn.value.match(/^[a-zA-Z /.]*$/i)) 
            {
              drn.focus();
              alert("Special characters are not allowed.");
              return;
            }
            return;
          }
          function checkpurpose(purpose)
          {
            if (purpose.value=="") 
            {
              purpose.focus();
              alert("Purpose must be entered");
              return;
            }
            else if (!drn.value.match(/^[a-zA-Z0-9 ().-;/]*$/i)) 
            {
              drn.focus();
              alert("Special characters are not allowed.");
              return;
            }
            return;
          }
          function checkrecv(recv)
          {
            if (recv.value=="") 
            {
              recv.focus();
              alert("Received by must be entered");
              return;
            }
            else if (!recv.value.match(/^[a-zA-Z ./]*$/i)) 
            {
              recv.focus();
              alert("Special characters are not allowed.");
              return;
            }
            return;
          }
          function log1()
          {
            window.location= "log1.asp"
          }
          function page1()
          {
            window.location="page1.asp"
          }
          function validate_form() 
          {
            var val = true;
            if(document.myform.per_name.value==''||document.myform.vech_no==''||document.myform.drv_name==''||document.myform.purpose=='')
              {
                val = false;
                break;
              }
            }
            return val;
          }
          </script>
          Code:
          <%
          Set CON1 = Server.CreateObject("ADODB.Connection")
          con1.open "Provider=MSDAORA.1;dsn=ops1;Password=gis;User ID=gis;Data Source=alpha2;Persist Security Info=True"
          SET RS1=SERVER.CREATEOBJECT("ADODB.RECORDSET")
          Set CON = Server.CreateObject("ADODB.Connection")
          con.open "Provider=MSDAORA.1;dsn=ops;Password=op;User ID=outpass;Data Source=intradb;Persist Security Info=True"
          SET RS=SERVER.CREATEOBJECT("ADODB.RECORDSET")
          SET RS2=SERVER.CREATEOBJECT("ADODB.RECORDSET")
          SET RS3=SERVER.CREATEOBJECT("ADODB.RECORDSET")
          SET RS4=SERVER.CREATEOBJECT("ADODB.RECORDSET")
          SET RS5=SERVER.CREATEOBJECT("ADODB.RECORDSET")
          
          ddd=DAY(DATE)
          mm=month(DATE)
          mmm=monthname(mm)
          yyy=year(DATE)
          if session("emp_no") = "" then
          %>
          <h2><font style="position:absolute;left:250;top:250">Session has been expired. Re-login please.</font></h2>
          <div style="position:absolute;left:300; top:400">
            <input type="button" style="width:100px" value="Login" onclick="log1()">
          </div> 
          <div style="position:absolute;left:550; top:400">
            <input type="button" style="width:100px" value="Exit" onclick="window.close();">
          </div> 
          <%else%>
          <body onload="document.myform.per_name.focus();" text=#000000 vLink=#330066 aLink=#666666 link=#000000 leftMargin=0 topMargin=0 marginwidth="0" marginheight="0">
          <form name="myform"  action="material.asp" method="post" onsubmit="return validate_form()" >
            <table cellSpacing="0" cellPadding="0" width="780" height="500" border="0">
              <tr>
                <td vAlign="top" align="right" width="180" height="500"></td>
                <td vAlign="top" align="left" width="600" bgColor="#ffffff">
                  <table cellSpacing="4" cellPadding="1" border="0" width="600" height="500" border="0">
                    <tbody bgcolor="cyan">
                      <tr>
                        <td colSpan="2">
                          <font face="Arial, Helvetica, sans-serif" color="#330066" size="2">
                            <center><h2><b>Preparation of Material Outpass</b></h2></center>
                          </font>
                        </td>
                      </tr>
                      <tr>
                        <td colSpan="2"><font face="Arial, Helvetica, sans-serif" size="2"><b>*</b>Indicates mandatory fields</FONT></TD>
                      </tr>
          <%          
                      set rs4=CON.EXECUTE("SELECT MAX(GP_NO) FROM GPS")
                      GPNO=CDBL(RS4(0))+1
          %>           
                      <tr>
                        <td><font style="width:225" face="Arial, Helvetica, sans-serif" size="2"><b>*Gatepass Number</b></font></td>
                        <td>
                          <font face="Arial, Helvetica, sans-serif" size="2"><%response.write GPNO%>
                            <input type="hidden" size="30" name="gno" value=<%=gpno%>>
                          </font>
                        </td>
                      </tr>
                      <tr>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"><b>*Name of the person taking the <br>&#160 material out</b></font></td>
                        <td>
                          <font face="Arial, Helvetica, sans-serif" size="2">
                            <input type="text" size="30" name="per_name" onblur="checkpn(this)">
                          </font>
                        </td>
                      </tr>
                      <tr>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"><b>*Transaction Type</b></font></td>
                        <td>
                          <select size="1" name="trans_type"> 
                            <option value="RE" selected>Returnable</option> 
                            <option value="NR">Not Returnable</option> 
                          </select>
                        </td>
                      </tr>
                      <tr>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"><b>*Issue Date</b></font></td>
                        <td><script>DateInput('issue_dt', true, 'DD/MM/YYYY')</script></td>
                      </tr>
                      <tr>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"><b>&#160 Expected Return Date</b></font></td>
                        <td><script>DateInput('exp_ret_dt', true, 'DD/MM/YYYY')</script></td>
                      </tr> 
                      <tr>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"><b>*Department </b></font></td>
                        <td>
          <%              
                          dim v_sectcd
          				dim v_sectname
                          set rs = con.execute("select dept from emp where emp_no = '" & session("emp_no")&"'")
          				rs.movefirst
          				v_sectcd = RS("dept")
          %>              
                          <font face="Arial, Helvetica, sans-serif" size="2">
          				  <select name="dept">	
          <%                  
                              set rs1 = con1.execute("select sectcode, sect_des from fms.br_sec_mas_akd ")
                              rs1.movefirst
          					do while not rs1.eof
                                if cint(v_sectcd) = cint(rs1("sectcode")) then
          %>                      
                                  <option value selected="<%=rs1("sectcode")%>"><%=rs1("sect_des")%></option>
          <%					  else%>
                                  <option Value="<%=rs1("sectcode")%>"><%=rs1("sect_des")%></option>
          <%
                                end if 
                                rs1.movenext
                              loop
          %>                  
                            </select>
                          </font>
                        </td>
                      </tr>
                      <tr>
                        <td><font face="Arial, Helvetica, sans-serif" size="2"><b>*Firm Name </b></font></td>
                        <td>
                          <font face="Arial, Helvetica, sans-serif" size="2">
                            <SELECT NAME="FIRM_NAME">
          <%                  
                              Set RS = CON.EXECUTE("SELECT Firm_name FROM firm ")
                              Do While Not RS.EOF
          %>                    
                                <option Value="<%=RS("firm_name")%>"><%=RS("FIRM_NAME")%></option>
          <%                    
                                RS.MoveNext
                              Loop
          %>                  
                            </SELECT>
                          </FONT>
                        </TD>
                      </TR>
                      <TR>
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><b>&#160Vehicle No.</b></FONT></TD>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <INPUT size="10" name="vech_no" value="N/A" onblur="check_vech_no(this)">
                          </FONT>
                        </TD>
                      </TR>
                      <TR>  
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><B>&#160Driver Name </B></FONT></TD>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <INPUT size="30" name="drv_name" value="N/A" onblur="checkdrn(this)">
                          </FONT>
                        </TD>
                      </TR>
                      <TR>
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><B>&#160Purpose</B></FONT></TD>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <INPUT size="30" name="purpose" value="N/A" onblur="checkpurpose(this)">
                          </FONT>
                        </TD>
                      </TR>
          Code:
          <%          
                      EMPNO=SESSION("EMP_NO")
                      SET RS2=CON1.EXECUTE("SELECT C.DEPTCODE FROM M_FIX_EMPLOYEE A, BR_DEP_MAS_AKD B, BR_SEC_MAS_AKD C WHERE A.DEPT_CD=C.SECTCODE  AND B.DEPTCODE=C.DEPTCODE AND A.EMPNO ='"& EMPNO &"'")
                      DEPT=RS2(0)
                      SET RS3=CON.EXECUTE("SELECT EMP_NO FROM EMP WHERE DEPT='"& DEPT &"' AND OPLEVEL='A' ")
          %>           
                      <TR>	
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><b>*Authorised By</b>(Employee No.)</FONT></TD>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <SELECT NAME="IAE">	
          <%                  
                              Do While Not RS3.EOF
                                SET RS5=CON1.EXECUTE("SELECT name FROM M_FIX_EMPLOYEE WHERE EMPNO ='"& rs3(0) &"'")
          %>                                                                           
                                <option Value="<%=RS3(0)%>"><%=RS3(0)&"-"&rs5(0)%></option>
          <%                    
                                RS3.MoveNext
                              Loop
          %>                  
                            </SELECT>
                          </FONT>
                        </TD>
                      </TR>
                      <TR>
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><b>*Prepared By </b>(Employee No.)</FONT></TD>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <INPUT size="10" name="pepd_by" readonly value=<%=session("emp_no")%>>
                          </FONT>
                        </TD>
                      </TR>
          	        <TR>
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><b>*Recieved By </b></font></TD>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <INPUT size="10" name="recv_by" onblur="checkrecv(this)">
                          </FONT>
                        </TD>
                      </TR>
                      <TR>
                        <TD><FONT face="Arial, Helvetica, sans-serif" size="2"><b>&#160Remarks </b></font></td>
                        <TD>
                          <FONT face="Arial, Helvetica, sans-serif" size="2">
                            <INPUT type="text" size="30" name="rem" value="N/A">
                          </FONT>
                        </TD>
                      </TR>
                      <TR>
                        <td align="center" colSpan="3">
                          <input type="button" style="width:100px" value="Back" name="back" onclick="page1()">
                          <input type="reset" style="width:100px" value="Clear" name="clear">
                          <input type="submit" style="width:100px" value="Submit" name="submit">
                        </td>
                      </TR>
                    </TBODY>
                  </TABLE>
                </TD>
              </tr>
            </TABLE>
          </FORM><!--END MAIN FORM TABLE-->
          </BODY>
          <%end if%>
          </HTML>
          Thanks and regards,
          Vikas

          Comment

          • acoder
            Recognized Expert MVP
            • Nov 2006
            • 16032

            #6
            If I've understood correctly from your ASP code, if the session variable is not set, only the following code is displayed in the browser (after the script tags):
            [html]<h2><font style="position :absolute;left: 250;top:250">Se ssion has been expired. Re-login please.</font></h2>
            <div style="position :absolute;left: 300; top:400">
            <input type="button" style="width:10 0px" value="Login" onclick="log1() ">
            </div>
            <div style="position :absolute;left: 550; top:400">
            <input type="button" style="width:10 0px" value="Exit" onclick="window .close();">
            </div> [/html]Is that correct?

            Comment

            • vikas251074
              New Member
              • Dec 2007
              • 198

              #7
              Yes Sir, It is correct.

              Thanks and regards,
              Vikas

              Comment

              • acoder
                Recognized Expert MVP
                • Nov 2006
                • 16032

                #8
                In which case, your code would look like this:
                Code:
                <title>Material Entry Form</title>
                <!--#include file="Hdr.asp"-->
                <script type="text/javascript" src="calendarDateInput.js">
                </script>
                <script type="text/javascript">
                function checkpn(pn)
                {
                  if (pn.value=="") 
                  {
                    pn.focus();
                    alert("Persons name must be entered");
                    return;
                  }
                  else if (!pn.value.match(/^[a-zA-Z .]*$/i))
                  {
                    pn.focus();
                    alert("Special characters are not allowed.");
                    return;
                  }
                  return;
                }
                function check_vech_no(vech_no)
                {
                  if (vech_no.value=="") 
                  {
                    vech_no.focus();
                    alert("Vehicle number must be entered");
                    return;
                  }
                  else if (!vech_no.value.match(/^[a-zA-Z0-9 ()-/]*$/i)) 
                  {
                    vech_no.focus();
                    alert("Special characters are not allowed.");
                    return;
                  }
                  return;
                }
                function checkdrn(drn)
                {
                  if (drn.value=="") 
                  {
                    drn.focus();
                    alert("Driver name must be entered");
                    return;
                  }
                  else if (!drn.value.match(/^[a-zA-Z /.]*$/i)) 
                  {
                    drn.focus();
                    alert("Special characters are not allowed.");
                    return;
                  }
                  return;
                }
                function checkpurpose(purpose)
                {
                  if (purpose.value=="") 
                  {
                    purpose.focus();
                    alert("Purpose must be entered");
                    return;
                  }
                  else if (!drn.value.match(/^[a-zA-Z0-9 ().-;/]*$/i)) 
                  {
                    drn.focus();
                    alert("Special characters are not allowed.");
                    return;
                  }
                  return;
                }
                function checkrecv(recv)
                {
                  if (recv.value=="") 
                  {
                    recv.focus();
                    alert("Received by must be entered");
                    return;
                  }
                  else if (!recv.value.match(/^[a-zA-Z ./]*$/i)) 
                  {
                    recv.focus();
                    alert("Special characters are not allowed.");
                    return;
                  }
                  return;
                }
                function log1()
                {
                  window.location= "log1.asp"
                }
                function page1()
                {
                  window.location="page1.asp"
                }
                function validate_form() 
                {
                  var val = true;
                  if(document.myform.per_name.value==''||document.myform.vech_no==''||document.myform.drv_name==''||document.myform.purpose=='')
                    {
                      val = false;
                      break;
                    }
                  }
                  return val;
                }
                </script>
                <h2><font style="position:absolute;left:250;top:250">Session has been expired. Re-login please.</font></h2>
                <div style="position:absolute;left:300; top:400">
                  <input type="button" style="width:100px" value="Login" onclick="log1()">
                </div> 
                <div style="position:absolute;left:550; top:400">
                  <input type="button" style="width:100px" value="Exit" onclick="window.close();">
                </div> 
                </HTML>
                If you check the error console, there are errors in the validate_form() function. There's an extra bracket and break; is not needed.

                Comment

                • vikas251074
                  New Member
                  • Dec 2007
                  • 198

                  #9
                  Oh I am very sorry for my carelessness sir.

                  You are right sir.

                  Now it is working. I have to very utmost carefull while code in big programme.

                  Thanks and regards,
                  Vikas

                  Comment

                  • acoder
                    Recognized Expert MVP
                    • Nov 2006
                    • 16032

                    #10
                    I would add one more thing: validate your markup using the W3C validator. At the moment, it's horribly invalid. Also, add a doctype to the top of your pages.

                    Comment

                    • vikas251074
                      New Member
                      • Dec 2007
                      • 198

                      #11
                      Yes sir,
                      How can I use W3C for validation? What is doctype?

                      Thanks and regards,
                      Vikas

                      Comment

                      • acoder
                        Recognized Expert MVP
                        • Nov 2006
                        • 16032

                        #12
                        See this article on doctypes. The link to the W3C validator is here. There are some more useful links here. If you have any problems or questions regarding your HTML, ask in the HTML forum.

                        Comment

                        • vikas251074
                          New Member
                          • Dec 2007
                          • 198

                          #13
                          Originally posted by acoder
                          See this article on doctypes. The link to the W3C validator is here. There are some more useful links here. If you have any problems or questions regarding your HTML, ask in the HTML forum.
                          OK Sir,
                          Thanks very much

                          Thanks and regard,
                          Vikas

                          Comment

                          • acoder
                            Recognized Expert MVP
                            • Nov 2006
                            • 16032

                            #14
                            You're welcome. Glad to help.

                            Comment

                            Working...