Jump to content

same javascript at two places doesnt work


mukeshprasad4u

Recommended Posts

HI ,

I am begineer in the field of webdesigning.

I am facing problem with a java script which is working at one places but doesnot at another.

 

Test.php -- working fine

 

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

<html>

<head>

<title>Untitled Document</title>

<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">

<meta http-equiv="Content-Style-Type" content="text/css">

<meta http-equiv="Content-Script-Type" content="text/javascript">

<script type="text/javascript">

var clone;

function cloneRow(){

var rows=document.getElementById('mytab').getElementsByTagName('tr');

var index=rows.length;

clone=rows[index-1].cloneNode(true);

var inputs=clone.getElementsByTagName('input'), inp, i=0,n ;

while(inp=inputs[i++]){

inp.name=inp.name.replace(/\d/g,'')+(index+1);

}

}

function addRow(){

var tbo=document.getElementById('mytab').getElementsByTagName('tbody')[0];

tbo.appendChild(clone);

cloneRow();

}

function addValue(obj){

obj.value=obj.value.replace(/[^\d]/,'');

var fields=document.getElementsByTagName('input'), i=0, tot=0, f;

while(f=fields[i++]){

f.name&&f.name.match(/cost/)?tot+=Number(f.value):null;

}

document.getElementsByName('sum')[0].value=tot;

}

onload=cloneRow;

</script>

</head>

<body>

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password="root"; // Mysql password

$db_name="teanest"; // Database name

 

// Connect to server and select databse.

$con=mysql_connect("$host", "$username", "$password");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("$db_name")or die("cannot select DB");

 

$sql="select id,name from items order by name";

$result = mysql_query ($sql);

 

$sql1="select id,name from suppliers order by name";

$result1=mysql_query($sql1);

?>

<form action="">

<table>

<tr>

<td align="right">Item Name:</td>

<td align="left">

 

</td>

</tr>

<tr>

<td align="right">Supplier:</td>

<td align="left">

<?php

echo "<select name=\"suppliers\" value=''>Supplier</option>";

// printing the list box select command

 

while($nt=mysql_fetch_array($result1)){//Array or records stored in $nt

echo "<option value=$nt[id]>$nt[name]</option>";

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

?>

</td>

<tr>

<td align="right">Date:</td>

<td align="left"><input id='start_dt' class='datepicker' name="date"/></td>

</tr>

<tr>

<td align="right">Bill No:</td>

<td align="left"><input type="text" size="10" name="billNo" /></td>

</tr>

</table>

 

<table id="mytab" border="1">

<tr>

<th>Sl No.</th>

<th>Item Name</th>

<th>Quantity</th>

<th>Unit</th>

<th>Cost Price</th>

</tr>

<tr>

<td><input type="text" size="3" name="slno"></td>

<td>

<?php

 

echo "<select name=\"items\" value=''>Item</option>";

// printing the list box select command

 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt

echo "<option value=$nt[id]>$nt[name]</option>";

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

?>

</td>

<td><input type="text" size="4" name="quantity"></td>

<td><input type="text" size="4" name="unit"></td>

<td><input type="text" size="4" name="costprice" onkeyup="addValue(this)"></td>

</tr>

</table>

<br>

<input type="button" value="Add a new row" onclick="addRow()">

<p>

Total: <input type="text" name="sum" readonly="readonly" value="Sum of Cost Price inputs">

</form>

</body>

</html>

 

 

 

receivings.php-- doesnot work ... same javascript included in header part

 

 

<?php

include 'includes/header.inc.php';

?>

<div class="sidebar1">

<br><br>

<ul class="nav">

<li><a href="#receive">Receive</a></li>

<li><a href="#">Link two</a></li>

<li><a href="#">Link three</a></li>

<li><a href="#">Link four</a></li>

</ul>

 

<!-- end .sidebar1 --></div>

 

<?php

$host="localhost"; // Host name

$username="root"; // Mysql username

$password="root"; // Mysql password

$db_name="teanest"; // Database name

 

// Connect to server and select databse.

$con=mysql_connect("$host", "$username", "$password");

if (!$con)

{

die('Could not connect: ' . mysql_error());

}

mysql_select_db("$db_name")or die("cannot select DB");

 

$sql="select id,name from items order by name";

$result = mysql_query ($sql);

 

$sql1="select id,name from suppliers order by name";

$result1=mysql_query($sql1);

?>

<div id="receive" class="modalDialog">

<div>

<a href="#close" title="Close" class="close">X</a>

<form name="receive" method="post" action="receive.php">

<fieldset>

<legend>Receive:</legend>

<table>

<tr>

<td align="right">Supplier:</td>

<td align="left">

<?php

echo "<select name=\"suppliers\" value=''>Supplier</option>";

// printing the list box select command

 

while($nt=mysql_fetch_array($result1)){//Array or records stored in $nt

echo "<option value=$nt[id]>$nt[name]</option>";

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

?>

</td>

<tr>

<td align="right">Date:</td>

<td align="left"><input id='start_dt' class='datepicker' name="date"/></td>

</tr>

<tr>

<td align="right">Bill No:</td>

<td align="left"><input type="text" size="10" name="billNo" /></td>

</tr>

</table>

<br><br>

<!--// receivings transaction table -->

<table id="mytab" border="1">

<tr>

<th>Sl No.</th>

<th>Item Name</th>

<th>Quantity</th>

<th>Unit</th>

<th>Cost Price</th>

</tr>

<tr>

<td><input type="text" size="3" name="slno"></td>

<td>

<?php

 

echo "<select name=\"items\" value=''>Item</option>";

// printing the list box select command

 

while($nt=mysql_fetch_array($result)){//Array or records stored in $nt

echo "<option value=$nt[id]>$nt[name]</option>";

/* Option values are added by looping through the array */

}

echo "</select>";// Closing of list box

?>

</td>

<td><input type="text" size="4" name="quantity"></td>

<td><input type="text" size="4" name="unit"></td>

<td><input type="text" size="4" name="costprice" onkeyup="addValue(this)"></td>

</tr>

</table>

<br>

<input type="button" value="Add a new row" onclick="addRow()">

<p>

Total: <input type="text" name="sum" readonly="readonly" value="Sum of Cost Price inputs">

</fieldset>

<input type="submit" value="Receive">

</form>

</div>

</div>

 

<div class="content">

<h1>List Of Receivings:</h1>

 

</div>

<!-- end .content --></div>

 

<?php

include 'includes/footer.inc.php';

?>

 

 

Please help !!!

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.