User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 402,031 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,482 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting

Why javascript does not work on firefox?

Join Date: Sep 2006
Posts: 83
Reputation: rinoa04 is on a distinguished road 
Rep Power: 2
Solved Threads: 4
rinoa04's Avatar
rinoa04 rinoa04 is offline Offline
Junior Poster in Training

Re: Why javascript does not work on firefox?

  #3  
Jul 26th, 2007
Here is part of the coding using C#. This is one of the module for ASP.NET web based system. Sorry if the coding are messy. The validation are mostly done using .NET validator in which is said to be javascript. Please correct me if I'm wrong.

// Interface
<%@ Page Language="C#" ContentType="text/html" ResponseEncoding="iso-8859-1" Inherits="AddShippingRates" Src="AddShippingRates.cs"%>
<%@ Register TagPrefix="uc1" TagName="InnovaBanner" Src="InnovaBanner.ascx" %>
<%@ Register TagPrefix="uc1" TagName="AdminLinks" Src="AdminLinks.ascx" %>
<%@ Register TagPrefix="uc1" TagName="copyrightfooter" Src="copyrightfooter.ascx" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
<title>InnovaCraft-AddShippingRates</title>
<link href="StyleAdmin.css" type=text/css rel=stylesheet>
</head>
<body>
<table width="806" height="589" border="1" align="center" cellpadding="0" cellspacing="0" bordercolor="#993333">
  <tr>
    <td width="817" height="16" bgcolor="#993333">&nbsp;</td>
  </tr>
  <tr>
    <td height="16" bgcolor="#993333" align="center"><uc1:InnovaBanner id="InnovaBanner1" runat="server"></uc1:InnovaBanner></td>
  </tr>
  <tr>
    <td height="16" bgcolor="#FFFFFF"><uc1:AdminLinks id="AdminLink1" runat="server"></uc1:AdminLinks></td>
  </tr>
  <tr>
    <td height="16" bgcolor="#993333"><span class="adminManagementTitle">Add Shipping Rates </span></td>
  </tr>
  <tr>
    <td height="16" bgcolor="#FFFFFF"><span class="welcome">Welcome&nbsp;&nbsp;&nbsp;
        <asp:Label ID="admin" runat="server" />        </span></td>
  </tr>
  <tr>
    <td height="600" valign="top" bgcolor="#FFFFFF"><form name="form1" method="post" runat="server">
      <table width="800" border="0" cellspacing="0" cellpadding="0">
        <tr>
          <td valign="top"><table width="792" border="0" align="left" cellpadding="0" cellspacing="0">
            <tr>
              <td colspan="6"><asp:Label ID="Message" Visible="false" runat="server" CssClass="adminContent"/></td>
            </tr>
            <tr>
              <td width="146"><span class="adminContent">Shipping Rate ID</span></td>
              <td colspan="5"><asp:TextBox ID="sidtxt" runat="server" Columns="5" ReadOnly="true" TextMode="SingleLine" /></td>
            </tr>
            <tr>
              <td><span class="adminContent">Country</span></td>
              <td colspan="5"><asp:TextBox ID="countrytxt" runat="server" TextMode="SingleLine" /></td>
            </tr>
            <tr>
              <td><span class="adminContent">Shipping Rate </span></td>
              <td colspan="5"><asp:TextBox ID="ratetxt" runat="server" TextMode="SingleLine" /></td>
            </tr>
            <tr>
              <td colspan="6">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td colspan="2">&nbsp;</td>
              <td width="78"><asp:Button ID="add" Text="Add" Width="60" runat="server" /></td>
              <td width="77"><asp:Button ID="reset" Text="Reset" runat="server" Width="60" CausesValidation="false" /></td>
              <td width="250"><asp:Button ID="cancel" Text="Cancel" runat="server" CausesValidation="false" /></td>
            </tr>
            <tr>
              <td colspan="6">&nbsp;</td>
            </tr>
          </table>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            </td>
        </tr>
        <tr>
          <td><table width="793" border="0" align="left" cellspacing="0">
            <tr>
              <td colspan="2"><asp:DataGrid AllowPaging="true" DataKeyField="ShippingRateID" ID="Shippingdg" runat="server" AutoGenerateColumns="false" OnPageIndexChanged="Paging" PageSize="5" Width="800" AlternatingItemStyle-CssClass="alternateRow">
                  <columns>
                  <asp:BoundColumn DataField="ShippingRateID" HeaderText="Shipping Rate ID" ReadOnly="true">
                    <headerstyle CssClass="dgheaderStyle"></headerstyle>
                    <itemstyle CssClass="dgitemStyle"></itemstyle>
                  </asp:BoundColumn>
                  <asp:BoundColumn DataField="DeliveryCountry" HeaderText="Country Destination">
                    <headerstyle CssClass="dgheaderStyle"></headerstyle>
                    <itemstyle CssClass="dgitemStyle"></itemstyle>
                  </asp:BoundColumn>
                  <asp:BoundColumn DataField="ShippingRates" HeaderText="Shipping Rates(USD)">
                    <headerstyle CssClass="dgheaderStyle"></headerstyle>
                    <itemstyle CssClass="dgitemStyle"></itemstyle>
                  </asp:BoundColumn>
                  <asp:TemplateColumn HeaderText="Edit">
                    <headerstyle CssClass="dgheaderStyle"></headerstyle>
                    <itemstyle CssClass="dgitemStyle"></itemstyle>
                    <itemtemplate>
                      <asp:HyperLink runat="server" Width="20" NavigateUrl='<%# "EditShippingRates.aspx?Shipping_ID=" + DataBinder.Eval(Container.DataItem, "ShippingRateID") %>' >Edit</asp:HyperLink>
                    </itemtemplate>
                  </asp:TemplateColumn>
                  <asp:TemplateColumn HeaderText="Delete">
                    <headerstyle CssClass="dgheaderStyle"></headerstyle>
                    <itemstyle CssClass="dgitemStyle"></itemstyle>
                    <itemtemplate>
                      <asp:CheckBox ID="delcb" runat="server"></asp:CheckBox>
                    </itemtemplate>
                  </asp:TemplateColumn>
                  </columns>
                  <pagerstyle HorizontalAlign="Right" Mode="NumericPages" CssClass="dgFooter"></pagerstyle>
              </asp:DataGrid></td>
            </tr>
            <tr>
              <td height="26" colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td>&nbsp;</td>
              <td><asp:Button ID="delete" Text="Delete Checked Item(s)" runat="server" CausesValidation="false" /></td>
            </tr>
            <tr>
              <td colspan="2">&nbsp;</td>
            </tr>
            <tr>
              <td><asp:RequiredFieldValidator ControlToValidate="countrytxt" Display="None" ErrorMessage="Country must not be empty" ID="empty1" runat="server" />          
                  <asp:RequiredFieldValidator ControlToValidate="ratetxt" Display="None" ErrorMessage="Shipping Rates must not be empty" ID="empty2" runat="server" />            
                  <asp:RegularExpressionValidator ControlToValidate="countrytxt" Display="None" ErrorMessage="Country must be alphabets" ID="v1" runat="server" ValidationExpression="[a-zA-Z]*" />            
                  <asp:RegularExpressionValidator ControlToValidate="ratetxt" Display="None" ErrorMessage="Rate must be in price format" ID="v2" runat="server" ValidationExpression="[0-9][0-9]*(\.+\d{2})?" />            
                &nbsp;</td>
              <td>&nbsp;</td>
            </tr>
            <tr>
              <td width="639"><asp:ValidationSummary DisplayMode="BulletList" HeaderText="ERROR:" ID="summary" runat="server" ShowMessageBox="true" ShowSummary="false"/>          
                &nbsp;</td>
              <td width="150">&nbsp;</td>
            </tr>
          </table>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p>&nbsp;</p>
            <p></p></td>
        </tr>
      </table>
    </form>
    </td>
  </tr>
  <tr>
    <td height="16" bgcolor="#FFFFFF"><uc1:copyrightfooter id="Copyrightfooter1" runat="server"></uc1:copyrightfooter></td>
  </tr>
</table>
</body>
</html>

// Coding for the logic
using System;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data;
using System.Data.SqlClient;
using System.Configuration;
using System.Web;
public class AddShippingRates : Page
{
 protected Label Message;
 protected Button add;
 protected DataGrid Shippingdg;
 protected TextBox sidtxt;
 protected TextBox ratetxt;
 protected TextBox countrytxt;
 protected Button reset;
 protected Button cancel;
 protected Button delete;
 protected Label admin;
 SqlConnection con;
 string db = ConfigurationSettings.AppSettings["constring"].ToString();
 #region Web Form Designer generated code
 override protected void OnInit(EventArgs e)
 {
  //
  // CODEGEN: This call is required by the ASP.NET Web Form Designer.
  //
  InitializeComponent();
  base.OnInit(e);
 }
  
 /// <summary>
 /// Required method for Designer support - do not modify
 /// the contents of this method with the code editor.
 /// </summary>
 private void InitializeComponent()
 {
  this.delete.Click += new System.EventHandler(this.Delete_Click);
  this.reset.Click += new System.EventHandler(this.Reset_Click);
  this.add.Click += new System.EventHandler(this.Add_Click);
  this.cancel.Click += new System.EventHandler(this.Cancel_Click);
 }
 #endregion
 private void Page_Load(object sender, System.EventArgs e)
 {
  // Disable caching in user's web browser works both in IE and Firefox
  Response.Cache.SetExpires(DateTime.Now.AddDays(-1));
  Response.Cache.SetCacheability(HttpCacheability.NoCache);
  Response.Cache.SetNoStore();
  // Disallowed user to browse the page when not login
  if ( Session["adminuser"] == null )
  {
   Response.Redirect("index.aspx");
  }
  admin.Text = Session["adminuser"].ToString();
  Message.Text = "";
  delete.Attributes.Add("OnClick", "return confirm('Are you sure to delete the item?');");
  try
  {
   con = new SqlConnection(db);
   
   getID();
   if ( !IsPostBack )
   {
    BindGrid();
   }
  }
  catch ( Exception ex )
  {
   Message.Text = "<b>ERROR: " + ex.Message;
   Message.Style["color"] = "red";
   Message.Visible = true;
  }
 }
 // Datagrid Binding
 private void BindGrid()
 {      
  SqlDataAdapter sda = new SqlDataAdapter("SELECT * FROM ShippingRates ORDER BY ShippingRateID DESC", con);
  DataSet ds = new DataSet();
  sda.Fill(ds, "ShippingRates");
  Shippingdg.DataSource=ds.Tables["ShippingRates"].DefaultView;
  Shippingdg.DataBind();
 }
 // Paging on datagrid
 public void Paging(object sender, DataGridPageChangedEventArgs e)
 {
  Shippingdg.CurrentPageIndex = e.NewPageIndex;
  Shippingdg.DataBind();
  BindGrid();
 }
 // Get next Shipping ID 
 private void getID()
 {
  SqlCommand maxId = new SqlCommand("SELECT MAX(ShippingRateID) FROM ShippingRates", con);
  con.Open();
  
  string result = maxId.ExecuteScalar().ToString(); 
  int id = Convert.ToInt32(maxId.ExecuteScalar().ToString());
  int getId = 1;
  
  if (  !result.Equals("") || !result.Equals("Null") )
  {
   getId = id + 1;
  }
  con.Close();
       
  sidtxt.Text = getId.ToString();
 }  
 // Add data to database
 public void Add_Click(object sender,  EventArgs e)
 { 
  int sid = Convert.ToInt32(sidtxt.Text);
  double rates = Convert.ToDouble(ratetxt.Text);
  string country = countrytxt.Text; 
 
  try
  {
   string exist = "SELECT COUNT(*) FROM ShippingRates WHERE DeliveryCountry = '"+country+"'";
   SqlCommand query = new SqlCommand(exist, con);
   con.Open();
  
   int yes = Convert.ToInt32(query.ExecuteScalar().ToString());
   if ( yes > 0 )
   {
    Message.Text = "<b>Error: " + country + " already exist in the database<br>";
    Message.Style["color"] = "red";
    Message.Visible = true;
   }
   else
   { 
    string insertQuery = "INSERT INTO ShippingRates VALUES ("+sid+", "+rates+", '"+country+"')";
    SqlCommand SqlCom = new SqlCommand(insertQuery, con);
    SqlCom.ExecuteNonQuery();
    Message.Text = "<b>Record has been Added<br>";
    Message.Style["color"] = "red";
    Message.Visible = true;
   }
  }
  catch ( SqlException )
  {
   Message.Text = "<b>ERROR: Problem with query";
   Message.Style["color"] = "red";
   Message.Visible = true;
  }
  con.Close();
  getID();
  ratetxt.Text = "";
  countrytxt.Text = "";
  BindGrid();
 }
 // Delete checked items
 private void Delete_Click(object sender, System.EventArgs e)
 {
  DataGridItem dgItem;
  CheckBox chkItem = new CheckBox();
  Shippingdg.CurrentPageIndex = 0;
   
  for ( int i = 0; i < Shippingdg.Items.Count; i++ )
  {
   dgItem = Shippingdg.Items[i];
   chkItem = (CheckBox)dgItem.FindControl("delcb");
     
   if ( chkItem.Checked == true )
   {
    int key = Convert.ToInt32(Shippingdg.DataKeys[dgItem.ItemIndex]);
    string deleteQuery = "DELETE FROM ShippingRates WHERE ShippingRateID = "+key+"";
    SqlCommand SqlCom = new SqlCommand(deleteQuery, con);
    SqlCom.Parameters.Add(new SqlParameter("@sid", SqlDbType.Int, 20));
    SqlCom.Parameters["@sid"].Value = Shippingdg.DataKeys[dgItem.ItemIndex];
    SqlCom.Connection.Open();
    try
    {
     SqlCom.ExecuteNonQuery();
     Message.Text = "<b>Record has been deleted</b><br>";
     Message.Style["color"] = "red";
     Message.Visible = true;
    }
    catch (SqlException)
    {
     Message.Text = "<b>ERROR: Could not delete record</b>";
     Message.Style["color"] = "red";
     Message.Visible = true;
    }
    SqlCom.Connection.Close();
   }
  }
  getID();
  BindGrid();
 }
 // Reset the form
 private void Reset_Click(object sender, System.EventArgs e)
 {
  countrytxt.Text = "";
  ratetxt.Text = "";
 }
 // Back to shipping rates main page
 private void Cancel_Click(object sender, System.EventArgs e)
 {
  Response.Redirect("ManageShippingRates.aspx");
 }
}
Reply With Quote  
All times are GMT -4. The time now is 10:36 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC