Tuesday 1 December 2015

create page (auth.php)

<?php
session_start();
if(!isset($_SESSION["username"])){
header("Location: login.php");
exit(); }
?>

create page (dashbord.php)

<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Dashboard - View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p>Welcome to Dashboard.</p>
<p><a href="index.php">Home</a><p>
<p><a href="insert.php">Insert New Record</a></p>
<p><a href="view.php">View Records</a><p>
<p><a href="logout.php">Logout</a></p>
</div>
</body>

</html>

create page (db.php)

<?php
$connection = mysql_connect('localhost', 'root', '');
if (!$connection){
    die("Database Connection Failed" . mysql_error());
}
$select_db = mysql_select_db('login');
if (!$select_db){
    die("Database Selection Failed" . mysql_error());
}

?>

create page (delete.php)

<?php 
require('db.php');
$id=$_REQUEST['id'];
$query = "DELETE FROM new_record WHERE id=$id"; 
$result = mysql_query($query) or die ( mysql_error());
header("Location: view.php"); 
 ?>

create page (edit.php)

<?php 
require('db.php');
include("auth.php");
$id=$_REQUEST['id'];
$query = "SELECT * from new_record where id='".$id."'"; 
$result = mysql_query($query) or die ( mysql_error());
$row = mysql_fetch_assoc($result);
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Update Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="dashboard.php">Dashboard</a> | <a href="insert.php">Insert New Record</a> | <a href="logout.php">Logout</a></p>
<h1>Update Record</h1>
<?php
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$id=$_REQUEST['id'];
$trn_date = date("Y-m-d H:i:s");
$name =$_REQUEST['name'];
$age =$_REQUEST['age'];
$submittedby = $_SESSION["username"];
$update="update new_record set trn_date='".$trn_date."', name='".$name."', age='".$age."', submittedby='".$submittedby."' where id='".$id."'";
mysql_query($update) or die(mysql_error());
$status = "Record Updated Successfully. </br></br><a href='view.php'>View Updated Record</a>";
echo '<p style="color:#FF0000;">'.$status.'</p>';
}else {
?>
<div>
<form name="form" method="post" action=""> 
<input type="hidden" name="new" value="1" />
<input name="id" type="hidden" value="<?php echo $row['id'];?>" />
<p><input type="text" name="name" placeholder="Enter Name" required value="<?php echo $row['name'];?>" /></p>
<p><input type="text" name="age" placeholder="Enter Age" required value="<?php echo $row['age'];?>" /></p>
<p><input name="submit" type="submit" value="Update" /></p>
</form>
<?php } ?>
</div>
</div>
</body>
</html>


create page (index.php)



<?php include("auth.php"); //include auth.php file on all secure pages ?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Welcome Home</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p>Welcome <?php echo $_SESSION['username']; ?>!</p>
<p>This is secure area.</p>
<p><a href="dashboard.php">Dashboard</a></p>
<a href="logout.php">Logout</a>
</div>
</body>
</html>

create page (insert.php)
<?php
require('db.php');
include("auth.php"); //include auth.php file on all secure pages
$status = "";
if(isset($_POST['new']) && $_POST['new']==1)
{
$trn_date = date("Y-m-d H:i:s");
$name =$_REQUEST['name'];
$age = $_REQUEST['age'];
$submittedby = $_SESSION["username"];
$ins_query="insert into new_record(`trn_date`,`name`,`age`,`submittedby`)values('$trn_date','$name','$age','$submittedby')";
mysql_query($ins_query) or die(mysql_error());
$status = "New Record Inserted Successfully.</br></br><a href='view.php'>View Inserted Record</a>";
}
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Insert New Record</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="dashboard.php">Dashboard</a> | <a href="view.php">View Records</a> | <a href="logout.php">Logout</a></p>
<div>
<h1>Insert New Record</h1>
<form name="form" method="post" action=""> 
<input type="hidden" name="new" value="1" />
<p><input type="text" name="name" placeholder="Enter Name" required /></p>
<p><input type="text" name="age" placeholder="Enter Age" required /></p>
<p><input name="submit" type="submit" value="Submit" /></p>
</form>
<p style="color:#FF0000;"><?php echo $status; ?></p>
</div>
</div>
</body>
</html>

create page (login.php)

<?php
/*
Author: Javed Ur Rehman
Website: https://htmlcssphptutorial.wordpress.com
*/
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Login</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
session_start();
    // If form submitted, insert values into the database.
    if (isset($_POST['username'])){
        $username = $_POST['username'];
        $password = $_POST['password'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
//Checking is user existing in the database or not
        $query = "SELECT * FROM `users1` WHERE username='$username' and password='".md5($password)."'";
$result = mysql_query($query) or die(mysql_error());
$rows = mysql_num_rows($result);
        if($rows==1){
$_SESSION['username'] = $username;
header("Location: index.php"); // Redirect user to index.php
            }else{
echo "<div class='form'><h3>Username/password is incorrect.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
}
    }else{
?>
<div class="form">
<h1>Log In</h1>
<form action="" method="post" name="login">
<input type="text" name="username" placeholder="Username" required />
<input type="password" name="password" placeholder="Password" required />
<input name="submit" type="submit" value="Login" />
</form>
<p>Not registered yet? <a href='registration.php'>Register Here</a></p>
</div>
<?php } ?>
</body>
</html>


create page (logout.php)

<?php
session_start();
if(session_destroy()) // Destroying All Sessions
{
header("Location: login.php"); // Redirecting To Home Page
}
?>

create page (registration.php)


<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>Registration</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<?php
require('db.php');
    // If form submitted, insert values into the database.
    if (isset($_POST['username'])){
        $username = $_POST['username'];
$email = $_POST['email'];
        $password = $_POST['password'];
$username = stripslashes($username);
$username = mysql_real_escape_string($username);
$email = stripslashes($email);
$email = mysql_real_escape_string($email);
$password = stripslashes($password);
$password = mysql_real_escape_string($password);
$trn_date = date("Y-m-d H:i:s");
        $query = "INSERT into `users1` (username, password, email, trn_date) VALUES ('$username', '".md5($password)."', '$email', '$trn_date')";
        $result = mysql_query($query);
        if($result){
            echo "<div class='form'><h3>You are registered successfully.</h3><br/>Click here to <a href='login.php'>Login</a></div>";
        }
    }else{
?>
<div class="form">
<h1>Registration</h1>
<form name="registration" action="" method="post">
<input type="text" name="username" placeholder="Username" required />
<input type="email" name="email" placeholder="Email" required />
<input type="password" name="password" placeholder="Password" required />
<input type="submit" name="submit" value="Register" />
</form>
</div>
<?php } ?>
</body>
</html>


create page (view.php)
<?php 
require('db.php');
include("auth.php");
?>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>View Records</title>
<link rel="stylesheet" href="css/style.css" />
</head>
<body>
<div class="form">
<p><a href="index.php">Home</a> | <a href="insert.php">Insert New Record</a> | <a href="logout.php">Logout</a></p>
<h2>View Records</h2>
<table width="100%" border="1" style="border-collapse:collapse;">
<thead>
<tr><th><strong>S.No</strong></th><th><strong>Name</strong></th><th><strong>Age</strong></th><th><strong>Edit</strong></th><th><strong>Delete</strong></th></tr>
</thead>
<tbody>
<?php
$count=1;
$sel_query="Select * from new_record ORDER BY id desc;";
$result = mysql_query($sel_query);
while($row = mysql_fetch_assoc($result)) { ?>
<tr><td align="center"><?php echo $count; ?></td><td align="center"><?php echo $row["name"]; ?></td><td align="center"><?php echo $row["age"]; ?></td><td align="center"><a href="edit.php?id=<?php echo $row["id"]; ?>">Edit</a></td><td align="center"><a href="delete.php?id=<?php echo $row["id"]; ?>">Delete</a></td></tr>
<?php $count++; } ?>
</tbody>
</table>
</div>
</body>
</html>

Wednesday 11 November 2015

Insert update delete in DataGridView in C#

Insert update delete in DataGridView in C#




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace AccountOpenning
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        DataTable dt = new DataTable();
        int i, j;
        int rowcount, sum;

        private void Form1_Load(object sender, EventArgs e)
        {
            dt.Columns.Add("S.No", typeof(int));
            dt.Columns.Add("Date", typeof(DateTime));
            dt.Columns.Add("Card No", typeof(int));
            dt.Columns.Add("Client Name", typeof(string));
            dt.Columns.Add("Product Name", typeof(string));
            dt.Columns.Add("Empty Bottle", typeof(int));
            dt.Columns.Add("Balance Account", typeof(int));
        }

        private void btnShow_Click(object sender, EventArgs e)
        {
            dt.Rows.Add(txtSno.Text, dateTimePicker1.Value, txtCno.Text, txtCname.Text, txtPname.Text, txtEbottle.Text, txtBaccount.Text);
            dataGridView1.DataSource = dt;

            txtSno.Text = null;
            txtCno.Text = null;
            txtCname.Text = null;
            txtEbottle.Text = null;
            txtPname.Text = null;
            txtBaccount.Text = null;
        }

        private void btnDelete_Click(object sender, EventArgs e)
        {
            try
            {
                dt.Rows.RemoveAt(dataGridView1.CurrentCell.RowIndex);
                dataGridView1.DataSource = dt;
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnExit_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void DataGridView1_CellClick(object sender, DataGridViewCellEventArgs e)
        {
            i = e.RowIndex;
            DataGridViewRow row = dataGridView1.Rows[i];
            txtSno.Text = row.Cells[0].Value.ToString();
            dateTimePicker1.Format = DateTimePickerFormat.Custom;
            txtCno.Text = row.Cells[2].Value.ToString();
            txtCname.Text = row.Cells[3].Value.ToString();
            txtPname.Text = row.Cells[4].Value.ToString();
            txtEbottle.Text = row.Cells[5].Value.ToString();
            txtBaccount.Text = row.Cells[6].Value.ToString();
        }

        private void btnUpdate_Click(object sender, EventArgs e)
        {
            DataGridViewRow row = dataGridView1.Rows[i];
            row.Cells[0].Value = txtSno.Text;
            row.Cells[1].Value = dateTimePicker1.Text;
            row.Cells[2].Value = txtCno.Text;
            row.Cells[3].Value = txtCname.Text;
            row.Cells[4].Value = txtPname.Text;
            row.Cells[5].Value = txtEbottle.Text;
            row.Cells[6].Value = txtBaccount.Text;
        }
    }
}

Monday 9 November 2015

Insert, Update And Delete in ASP.NET



Data Base Design




create database Form

use Form

create table Employee
(
[ID] int identity primary key,
[Name] varchar (25),
[Email] varchar (25),
[Password] varchar (25),
);

select * from Employee


Insert, Update And Delete in ASP.NET






<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="WebApplication6.WebForm1" %>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
</head>
<body>
    <form id="form1" runat="server">
    <div>
   
        <asp:TextBox ID="txtName" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtEmail" runat="server"></asp:TextBox>
        <br />
        <asp:TextBox ID="txtPass" runat="server" TextMode="Password"></asp:TextBox>
        <br />
        <br />
        <asp:TextBox ID="txtUpdate" runat="server"></asp:TextBox>
        <br />
        <br />
        <asp:Button ID="btnInsert" runat="server" OnClick="btnInsert_Click" Text="Insert" />
        <asp:Button ID="btnUpdate" runat="server" Text="Update" OnClick="btnUpdate_Click" />
        <asp:Button ID="btnDelete" runat="server" Text="Delete" OnClick="btnDelete_Click" />
   
    </div>
    </form>
</body>
</html>



Insert, Update And Delete Coding in ASP.NET


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;
using System.Configuration;

namespace WebApplication6
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }
        string path = ConfigurationManager.ConnectionStrings["FormConnectionString"].ConnectionString;
        protected void btnInsert_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(path);
            SqlCommand cmd = new SqlCommand("insert into Employee values('" + txtName.Text + "','" + txtEmail.Text + "', '" + txtPass.Text + "')", con);
            con.Open();
            cmd.ExecuteNonQuery();

            txtName.Text = "";
            txtEmail.Text = "";
            txtPass.Text = "";
        }

        string Update = ConfigurationManager.ConnectionStrings["FormConnectionString"].ConnectionString;
        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(Update);
            SqlCommand cmd = new SqlCommand("update Employee set Name='"+txtName.Text+"', Email='"+txtEmail.Text+"', Password='"+txtPass.Text+"' where id = '"+txtUpdate.Text+"' ", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            txtUpdate.Text = "";
            txtName.Text = "";
            txtEmail.Text = "";
            txtPass.Text = "";

        }

        protected void btnDelete_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(Update);
            SqlCommand cmd = new SqlCommand("delete from Employee where id = '" + txtUpdate.Text + "' ", con);
            con.Open();
            cmd.ExecuteNonQuery();
            con.Close();

            txtUpdate.Text = "";
            txtName.Text = "";
            txtEmail.Text = "";
            txtPass.Text = "";
        }

       
    }
}


Wednesday 4 November 2015

Create Insert AND Update Form


DataBase Create




Create Insert AND Update Form





using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;
using System.Data.Sql;

namespace databaseconnection
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnInsert_Click(object sender, EventArgs e)
        {

         string path = "Data Source=.;Initial Catalog=connection;Persist Security Info=True;User ID=sa;Password=123";
         SqlConnection con = new SqlConnection(path);

         SqlCommand cmd = new SqlCommand("insert into Register values ('" + txtName.Text + "', '" + txtEmail.Text + "')", con);
         con.Open();
         cmd.ExecuteNonQuery();

         txtName.Text = "";
         txtEmail.Text = "";
            

            
        }

        protected void btnUpdate_Click(object sender, EventArgs e)
        {
            string path = "Data Source=.;Initial Catalog=connection;Persist Security Info=True;User ID=sa;Password=123";
            SqlConnection con = new SqlConnection(path);

            SqlCommand cmd = new SqlCommand("UPDATE Register SET Name='" + txtName.Text + "',Email ='" + txtEmail.Text + "' where ID='"+txtUpdate.Text+"'", con);
            con.Open();
            cmd.ExecuteNonQuery();

            txtName.Text = "";
            txtEmail.Text = "";
            
        }
    }

}

Monday 26 October 2015

Data Transfer in asp.net



WebForm1 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPproject
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Server.Transfer("WebForm2.aspx");
        }

        public string Name
        {
            get {
                return txtName.Text;
            }
     
        }
        public string Email
        {
            get {
                return txtEmail.Text;
            }
        }
    }
}






                                                                        WebForm2 


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace ASPproject
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //Page lastPage=(Page)Context.Handler;
            //lblName.Text = ((TextBox)lastPage.FindControl("txtName")).Text;
            //lblEmail.Text = ((TextBox)lastPage.FindControl("txtEmail")).Text;


        }
    }
}

Wednesday 21 October 2015

Page Navigation Server.Transver








using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;

namespace Asp_Project
{
    public partial class WebForm1 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {

        }

        protected void btnTransfer_Click(object sender, EventArgs e)
        {
            Server.Transfer("~/WebForm2.aspx", false);
        }

        protected void btnredirec_Click(object sender, EventArgs e)
        {
            Response.Redirect("~/WebForm2.aspx");
        }

     
    }
}














using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Collections.Specialized;

namespace Asp_Project
{
    public partial class WebForm2 : System.Web.UI.Page
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            //NameValueCollection previousformCollection = Request.Form;
            //lblName.Text = previousformCollection["txtName"];
            //lblEmail.Text = previousformCollection["txtEmail"];

            Page perviouspage = Page.PreviousPage;

            if (perviouspage != null)
            {
                lblName.Text = ((TextBox)perviouspage.FindControl("txtName")).Text;
                lblEmail.Text = ((TextBox)perviouspage.FindControl("txtName")).Text;
            }

         
         
        }
    }
}

Wednesday 7 October 2015

Login/Registration Form in C# window Application Form


Login.cs







using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace user_login
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(@"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True");
            con.Open();
            SqlCommand cmd = new SqlCommand("Select * from comsoul_registration where Fname = '"+txtUser.Text+"' and Password = '"+txtPass.Text+"'", con );
            SqlDataReader reader = cmd.ExecuteReader();
         
            int count = 0;
            while(reader.Read())
            {
                count += 1;
            }
            if (count == 1)
            {
                MessageBox.Show("OK");
                Registraion f2 = new Registraion();
                f2.Show();
            }
            else if(count > 0){
                MessageBox.Show("Doublicate user and Password");
         
            }
            else{
                MessageBox.Show("UserName and Password not correct");
            }

            txtUser.Clear();
            txtPass.Clear();
     }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
     
    }
}



Registraion.cs




using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Data.Sql;
using System.Data.SqlClient;


namespace user_login
{
    public partial class Registraion : Form
    {
        //C:\Program Files (x86)\Microsoft SQL Server\100\Tools\Binn\VSShell\Common7\IDE

        string path = @"Data Source=ASP4-PC\SQLEXPRESS;Initial Catalog=comsoul1;Integrated Security=True";

        public Registraion()
        {
            InitializeComponent();
        }

        private void btnregister_Click(object sender, EventArgs e)
        {
            SqlConnection con = new SqlConnection(path);
            if (con.State != ConnectionState.Open)
            {
                con.Open();
                string addquery = string.Format("insert into comsoul_registration (Fname,Lname, Phone, Street, Zip_code, Email, Password,Re_enter, Creadit_card,Creadit_card_type,Date_Time) values('" + 
                                                                                        txtFname.Text + "','" + txtLname.Text + "','" + txtPhone.Text + "', '" + txtStreet.Text + "', '" + txtZip.Text + "','" + txtEmail.Text + "','" + txtPassword.Text + "', '" + txtRepassword.Text + "','" + txtCcard.Text + "','" + txtCcard2.Text + "','" + txtdate.Value.Date + "')");

                SqlCommand cmd = new SqlCommand(addquery,con);

                var roweffected = cmd.ExecuteNonQuery();


                MessageBox.Show("Inserted Data !");

                txtFname.Text = null;
                txtLname.Text = null;
                txtPhone.Text = null;
                txtStreet.Text = null;
                txtZip.Text = null;
                txtEmail.Text = null;
                txtPassword.Text = null;
                txtRepassword.Text = null;
                txtCcard.Text = null;
                txtCcard2.Text = null;
              
            }
            else
            {
                con.Close();

            }

        }

        private void btncancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }
    }
}





database





create  database comsoul1
  
  create table comsoul_registration
  (
id int primary key identity,
[Fname] varchar (50),
[Lname] varchar (50),
[Phone] int,
[Street] varchar (50),
[City] varchar (50),
[Zip_code] int,
[Email] varchar (50),
[Password] varchar (50),
[Re-enter] varchar (50),
[Creadit_card] int,
[Creadit_card_type] varchar (50),
  )
  
  alter table comsoul_registration
  add [Date_Time] datetime
  
  select * from comsoul_registration 


Friday 11 September 2015



<html>

<head>
<TITLE>ROW Add</TITLE>

    <script type="text/javascript">

function displayResult(j)
{
    if (j <= document.getElementById("purchaseItems").rows.length) {
        for (var i= document.getElementById("purchaseItems").rows.length; i>j ;i--) {
            var elName = "addRow[" + i + "]";
            var newName = "addRow[" + (i+1) + "]";
            var newClick = "displayResult(" + (i+1) + ")";
            var modEl = document.getElementsByName(elName);

            modEl.setAttribute("onclick", newClick);
            document.getElementsByName("addRow[" + i + "]").setAttribute('name', "addRow[" + (i+1) + "]");
        }
    }
    var table=document.getElementById("purchaseItems");
    var row=table.insertRow(j);
    var cell1=row.insertCell(0);
    var cell2=row.insertCell(1);
    var cell3=row.insertCell(2);
    var cell4=row.insertCell(3);
    var cell5=row.insertCell(4);
    cell1.innerHTML="<input type=text class='tbDescription' name='description[]' required/>";
    cell2.innerHTML="<input type=text name='itemPrice[]' required />";
    cell3.innerHTML="<input type=text name='itemquantity[]' required />";
    cell4.innerHTML="<input type='text' name='lineTotal[]' readonly />";
    cell5.innerHTML="<input type='button' name='addRow["+ j + "]' class='add' onclick=\"displayResult(" + (j+1) + ")\" value='+' />";
}
    </script>



</head>
<body>
<h2>Add Row </h2>


<table id= "purchaseItems" name="purchaseItems" align="center">
<tr>
    <th>Description</th>
    <th>price</th>
    <th>quantity</th>
    <th>Line Total</th>
    <td>&nbsp;</td>
</tr>
<tr>
    <td><input type="text" name="description[]" class="tbDescription" required /></td>
    <td><input type="text" name="price[]" required /></td>
    <td><input type="text" name="quantity[]" required /></td>
    <td><input type="text" name="lineTotal[]" readonly /></td>
    <td><input type="button" name="addRow[1]" onclick="displayResult(2)" class="add" value='+' /></td>
</tr>
</table>
</body>

</html>


<html>

<head>
<TITLE>ROW Add</TITLE>

    <script type="text/javascript">
function addRow() {
       
    var myName = document.getElementById("name");
    var age = document.getElementById("age");
    var table = document.getElementById("myTableData");

    var rowCount = table.rows.length;
    var row = table.insertRow(rowCount);

    row.insertCell(0).innerHTML= '<input type="button" value = "Delete" onClick="Javacsript:deleteRow(this)">';
    row.insertCell(1).innerHTML= myName.value;
    row.insertCell(2).innerHTML= age.value;

}

function deleteRow(obj) {
   
    var index = obj.parentNode.parentNode.rowIndex;
    var table = document.getElementById("myTableData");
    table.deleteRow(index);
 
}

function addTable() {
   
    var myTableDiv = document.getElementById("myDynamicTable");
   
    var table = document.createElement('TABLE');
    table.border='1';
 
    var tableBody = document.createElement('TBODY');
    table.appendChild(tableBody);
   
    for (var i=0; i<3; i++){
       var tr = document.createElement('TR');
       tableBody.appendChild(tr);
     
       for (var j=0; j<4; j++){
           var td = document.createElement('TD');
           td.width='75';
           td.appendChild(document.createTextNode("Cell " + i + "," + j));
           tr.appendChild(td);
       }
    }
    myTableDiv.appendChild(table);
 
}

function load() {
 
    console.log("Page load finished");

}
    </script>



</head>
<body onload="load()">
<div id="myform">
<b>Simple form with name and age ...</b>
<table>
    <tr>
        <td>Name:</td>
        <td><input type="text" id="name"></td>
    </tr>
    <tr>
        <td>Age:</td>
        <td><input type="text" id="age">
        <input type="button" id="add" value="Add" onclick="Javascript:addRow()"></td>
    </tr>
    <tr>
        <td>&nbsp;</td>
        <td>&nbsp;</td>
    </tr>
</table>
</div>
<div id="mydata">
<b>Current data in the system ...</b>
<table id="myTableData"  border="1" cellpadding="2">
    <tr>
        <td>&nbsp;</td>
        <td><b>Name</b></td>
        <td><b>Age</b></td>
    </tr>
</table>
&nbsp;

</div>
<div id="myDynamicTable">
<input type="button" id="create" value="Click here" onclick="Javascript:addTable()">
to create a Table and add some data using JavaScript
</div>
</body>

</html>

Tuesday 8 September 2015

Marksheet Codes in Javascript with HTML and CSS


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Mark Sheet</title>
<link rel="stylesheet" href="domi.css" />

<script>
function myfunction(){
var a = document.form1.txtname.value;
document.getElementById("name").innerHTML=a;
var b = document.form1.txtfame.value;
document.getElementById("fname").innerHTML = b;
var c = document.form1.txtinstitute.value;
document.getElementById("inst_name").innerHTML = c;
var d = document.form1.txtbatch.value;
document.getElementById("batch").innerHTML = d;
var e = document.form1.txtaccount.value;
document.getElementById("account").innerHTML = e;
var f = document.form1.txtdesign.value;
document.getElementById("designing").innerHTML = f;
var g = document.form1.txtmath.value;
document.getElementById("math").innerHTML = g;
var h = document.form1.txtdevelop.value;
document.getElementById("develop").innerHTML = h;

var txt1 = eval(parseFloat(document.form1.txtaccount.value)+parseFloat(document.form1.txtdesign.value)+parseFloat(document.form1.txtmath.value)+parseFloat(document.form1.txtdevelop.value));
document.getElementById("total").innerHTML = txt1;

var txt2 =eval(parseFloat(txt1*100)/400);
document.getElementById("percent").innerHTML = txt2.toFixed(2)+"%";


switch(true)
{
case(txt2>=80):
document.getElementById("grade").innerHTML="A1";
break;
case(txt2>=70):
document.getElementById("grade").innerHTML="A";
break;
case(txt2>=60):
document.getElementById("grade").innerHTML="B";
break;
case(txt2>=50):
document.getElementById("grade").innerHTML="C";
break;
case(txt2>=40):
document.getElementById("grade").innerHTML="D";
break;
case(txt2<40):
document.getElementById("grade").innerHTML="Fail";
break;
}

}


</script>

</head>

<body>
<div id="container">

<div class="marksheet">
<h1>STUDENT MARKSHEET</h1>

<fieldset>
<legend>Student Information</legend>
<table id="tbl1">
<form name="form1">
<tr>
<td>Name:</td><td><input type="text" name="txtname" /> </td>
<td>&nbsp; &nbsp; Father Name:</td><td><input type="text" name="txtfame" /></td>
</tr>
<tr>
<td>Institute Name:</td><td><input type="text" name="txtinstitute" /></td>
<td>&nbsp; &nbsp; Batch:</td><td><input type="numb" name="txtbatch" /></td>
</tr>
</table>
</fieldset>
<br /><br />

<fieldset>
<legend>Suject Remarks</legend>
<table height="232" id="tbl2">
<tr>
<td width="140">Accounting</td><td><input type="text" name="txtaccount" maxlength="2" size="10" />
&nbsp; Out of 100</td>
</tr>
<tr>
<td width="140">Web Designin</td><td><input type="text" name="txtdesign" size="10" maxlength="2" />
&nbsp; Out of 100</td>
</tr>
<tr>
<td width="140">Mathematic</td><td><input type="text" name="txtmath" maxlength="2" size="10" />
&nbsp; Out of 100</td>
</tr>
<tr>
<td width="140">Web Development</td><td><input type="text" name="txtdevelop" maxlength="2"  size="10" />
&nbsp; Out of 100
</td>
</tr>
</table>
<div class="btn">
<button type="button" onclick="myfunction()">Submitt</button>
<button type="reset" name="reset">Reset</button>
</div>
</fieldset>
</form>


<div class="std_info">
<table border="1">
<tr>
<th colspan="2" width="240">Student Information</th>
</tr>
<tr>
<td width="135">Name:</td><td><FONT face="arial" id="name"></FONT></td>
</tr>
<tr>
<td width="135">Father Name:</td><td><font face="arial" id="fname"></font></td>
</tr>
<tr>
<td width="135">Institute Name:</td><td><font face="arial" id="inst_name"></font></td>
</tr>
<tr>
<td width="135">Batch:</td><td><font face="arial" id="batch"></font></td>
</tr>



<tr>
<th colspan="2" width="135">Subject Remarks</th>
</tr>
<tr>
<td width="135">Accounting:</td><td><font face="arial" id="account"></font></td>
</tr>
<tr>
<td  width="135">Web Designing:</td><td><font face="arial" id="designing"></font></td>
</tr>
<tr>
<td width="135">Mathematic:</td><td><font face="arial" id="math"></font></td>
</tr>
<tr>
<td width="135">Web Development:</td><td><font face="arial" id="develop"></font></td>
</tr>


<tr>
<th colspan="2" width="140">Subject Remarks</th>
</tr>
<tr>
<td width="135">Total:</td><td><font face="arial" id="total"></font></td>
</tr>
<tr>
<td width="135">Percentage:</td><td><font face="arial" id="percent"></font></td>
</tr>
<tr>
<td width="135">Grade:</td><td><font face="arial" id="grade"></font></td>
</tr>

</table>
</div>

</div><!--marksheet-->
</div><!--container-->
</body>
</html>