onChange

  • (2 Pages)
  • +
  • 1
  • 2

23 Replies - 4555 Views - Last Post: 02 September 2007 - 01:06 AM

#1 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

onChange

Posted 31 August 2007 - 02:32 AM

Hi... need help again guys.. I wanted to change the values of total field after I inputted something on the bQuantity field... Spend the night trying to solve but it would not work here are the codes


 <?php
 
include 'connect.php';
$sName=$_GET['sName'];

$query = "Select * from products where sName ='$sName'";
$result = mysql_query($query) or die(mysql_error());
			
   
			while($array=mysql_fetch_array($result))
							   {
								extract($array);
								
								
								 $sName=$sName;
								 $category=$category;
								 $description=$description;
								 $price=$price;
								 $quantity=$quantity;
								 $image=$image;

								  
								}
								?>
								
								

								


<html>
<head>
<title>Buy</title>
<style type="text/css">
<!--
.style1 {font-weight: bold}
.style2 {
	color: #0000FF;
	font-style: italic;
	font-weight: bold;
}
-->
</style>
</head>

<body leftmargin="0" topmargin="0" marginwidth="0" marginheight="0">
<table width="780" border="0" align="center" cellpadding="0" cellspacing="0" bgcolor="#254D5E">
  <tr>
	<td><table width="780" border="0" cellspacing="0" cellpadding="0">
	  <tr>
		<td height="5"></td>
	  </tr>
	  <tr>
		<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
		  <tr>
			<td>&nbsp;</td>
			<td width="720" align="center"><table width="720" border="0" cellspacing="0" cellpadding="0">
			  <tr>
				<td background="images/h_bg.jpg"><table width="100%" border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td width="81"><img src="images/h_1.jpg" alt="" width="81" height="219"></td>
					<td align="right" valign="middle" background="images/h_bg.jpg"><table width="90%"  border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td height="54">&nbsp;</td>
					  </tr>
					  <tr>
						<td><strong><span class="style2"><span class="style8"><em><font size="100">Softlandia</font></em></span></strong></td>
					  </tr>
					  <tr>
						<td><div align="left" class="style10"><em><strong>Fast and Secure</strong></em></div></td>
					  </tr>
					</table></td>
					<td width="368" align="right"><img src="images/h_2.jpg" alt="" width="250" height="219"></td>
				  </tr>
				</table></td>
			  </tr>
			  
			  
			  <tr>
				<td><table width="100%"  border="0" cellspacing="0" cellpadding="0">
				  <tr>
					<td><img src="images/box_top.gif" alt="" width="720" height="6"></td>
				  </tr>
				  <tr>
					<td><table width="100%" border="0" cellspacing="0" cellpadding="0">
					  <tr>
						<td width="195" align="center" valign="top" bgcolor="#AFF7FA"><br>
						  <table width="87%" border="0" cellspacing="0" cellpadding="0">
						  <tr>
							<td align="center" valign="top"><table width="100%"  border="0" cellspacing="2" cellpadding="0">
							  <tr>
								<td bgcolor="#32B4B9" class="stylel15"><table width="100%"  border="0" cellspacing="0" cellpadding="4">
								  <tr>
									<td width="28" align="center"><img src="images/arrow.gif" width="13" height="7" alt="" /></td>
									<td><font color="#3333FF"><span class="style1">Home</span></font></td>
								  </tr>
								</table></td>
							  </tr>
							  <tr>
								<td bgcolor="#32B4B9" class="stylel15"><table width="100%"  border="0" cellspacing="0" cellpadding="4">
								  <tr>
									<td width="28" align="center"><img src="images/arrow.gif" width="13" height="7" alt="" /></td>
									<td><span class="style1"><a href="Login.php"><font color="#3300FF">Login </font></a></span></td>
								  </tr>
								</table></td>
							  </tr>
							  <tr>
								<td bgcolor="#32B4B9" class="stylel15"><table width="100%"  border="0" cellspacing="0" cellpadding="4">
								  <tr>
									<td width="28" align="center"><img src="images/arrow.gif" width="13" height="7" alt="" /></td>
									<td><span class="style1"><a href="Register.php"><font color="#3300FF">Register</font></a></span></td>
								  </tr>
								</table></td>
							  </tr>
							  <tr>
								<td bgcolor="#32B4B9" class="stylel15"><table width="100%"  border="0" cellspacing="0" cellpadding="4">
								  <tr>
									<td width="28" align="center"><img src="images/arrow.gif" width="13" height="7" alt="" /></td>
									<td><span class="style1"><a href="Softwares.php"><font color="#3300FF">Softwares</font></a></span></td>
								  </tr>
								</table></td>
							  </tr>
							  <tr>
								<td bgcolor="#32B4B9" class="stylel15"><table width="100%"  border="0" cellspacing="0" cellpadding="4">
								  <tr>
									<td width="28" align="center"><img src="images/arrow.gif" width="13" height="7" alt="" /></td>
									<td><span class="style1"><a href="java script:void(0);">About Us</a></span></td>
								  </tr>
								</table></td>
							  </tr>
							</table>
							  </td>
						  </tr>
						  <tr>
							<td align="left" valign="top">&nbsp;</td>
						  </tr>
						</table></td>
						<td width="517" align="center" valign="top" bgcolor="#FFFFFF"><table width="92%"  border="0" cellspacing="0" cellpadding="0">
						  <tr>
							<td height="35"><span class="style2">Welcome To Softlandia</span></td>
						  </tr>
						  <tr>
							<td align="left" valign="top" class="style11"><p align="center"><object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="70" height="28">
								<param name="movie" value="Home.swf">
								<param name="quality" value="high">
								<embed src="Home.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="70" height="28" ></embed>
							  </object>
							  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="70" height="28">
								<param name="movie" value="Login.swf">
								<param name="quality" value="high">
								<embed src="Login.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="70" height="28" ></embed>
							  </object>
							  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="70" height="28">
								<param name="movie" value="Register.swf">
								<param name="quality" value="high">
								<embed src="Register.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="70" height="28" ></embed>
							  </object>
							  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="70" height="28">
								<param name="movie" value="Softwares.swf">
								<param name="quality" value="high">
								<embed src="Softwares.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="70" height="28" ></embed>
							  </object>
							  <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0" width="70" height="28">
								<param name="movie" value="About.swf">
								<param name="quality" value="high">
								<embed src="About.swf" quality="high" pluginspage="http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash" type="application/x-shockwave-flash" width="70" height="28" ></embed>
							  </object>
							  <?php
						
							
							if($_SESSION['username']!=NULL){
						   					 
							 echo" <object classid=\"clsid:D27CDB6E-AE6D-11cf-96B8-444553540000\" codebase=\"http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=5,0,0,0\" width=\"70\" height=\"28\">
								<param name=\"movie\" value=\"Customer.swf\">
								<param name=\"quality\" value=\"high\">
								<embed src=\"Customer.swf\" quality=\"high\" pluginspage=\"http://www.macromedia.com/shockwave/download/index.cgi?P1_Prod_Version=ShockwaveFlash\" type=\"application/x-shockwave-flash\" width=\"70\" height=\"28\" ></embed>
							  </object>";
							  }?>
</p>


<script TYPE="text/javascript">
<!--
function total(total)
{
if (bQuantity.inchange)return;
total.inchange=true;
total.value=total.value*bQuantity.value;
total.inchange=false;
}
//-->
</SCRIPT>
								
		<p><strong> <font color="#0000FF">Softlandia User System -&gt; Buy Product</font></strong></p>
							  <table width="440" height="391" border="0" align="center">
							  <form action="" method="post">
								<tr>
								  <td width="178" height="387"><img src="" alt="" name="image" width="150" height="240" id="image"></td>
								  <td width="225"><table width="237" height="330" border="0">
									  <tr>
										<td height="30"><span class="style1">Name</span>										  <input name="sName" type="text" id="sName" value="<?php echo "$sName"; ?>" disabled></td>
									  </tr>
									  <tr>
										<td height="30"><strong>Category 
											<input name="category" type="text" id="category2" value="<?php echo "$category"; ?>" disabled>
										</strong></td>
									  </tr>
									  <tr>
										<td height="30"><strong>Description 
										  </strong>										  <textarea name="description"  disabled cols="30" id="description"><?php echo "$description"; ?> </textarea></td>
									  </tr>
									  <tr>
										<td height="30"><strong>Price 
										  <input name="price" type="text" id="price" value="<?php echo "$price"; ?>" disabled>
										</strong></td>
									  </tr>
									  <tr>
										<td height="30"><strong>Quantity 
										  <input name="quantity" type="text" id="quantity" value="<?php echo "$quantity"; ?>">
										</strong></td>
									  </tr>
									  <tr>
										<td height="30"><strong>No. of items to be purchased 
										  
											<input name="bQuantity" type="text" id="bQuantity" onchange="total(this)">
</strong></td>
									  </tr>
									  <tr>
										<td height="30"><strong>Total 
										  <input name="total" type="text" id="total" value="00.00" onchange="total(this)" disabled>
										</strong></td>
									  </tr>
								  </table></td>
								</tr>
								</form>
							  </table>
							  <p align="center"> <a href="Card.php?sName=".$sName."&username="$username">
								<input name="buy" type="submit" id="buy" value="Buy Product">
								</a> &nbsp; &nbsp;
								<a href="Reserve_proc.php?sName=".$sName."&quantity=".$bQuantity"&total=".$total><input name="reserve" type="button" value="Reserve">
							  </p>							  <p align="center">&nbsp;							  </p>
							</table></td>
						</tr>
					</table></td>
				  </tr>
				  <tr>
					<td><img src="images/box_bottom.gif" alt="" width="720" height="6"></td>
				  </tr>
				</table></td>
			  </tr>
			</table></td>
			<td>&nbsp;</td>
		  </tr>
		</table></td>
	  </tr>
	  <tr>
		<td height="30" align="center"><span class="style7">Copyright &copy; 2007 Softlanida Inc. All rights reserved. </span></td>
	  </tr>
	</table></td>
  </tr>
</table>
</body>
</html>




Is This A Good Question/Topic? 0
  • +

Replies To: onChange

#2 dyne  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 4
  • Joined: 30-August 07

Re: onChange

Posted 31 August 2007 - 02:50 AM

View Postantiturncoat, on 31 Aug, 2007 - 02:32 AM, said:

								 $sName=$sName;
								 $category=$category;
								 $description=$description;
								 $price=$price;
								 $quantity=$quantity;
								 $image=$image;



It's not the fault, but what's that good for? I think you should kick that out.
Was This Post Helpful? 0
  • +
  • -

#3 snoj  Icon User is offline

  • Married Life
  • member icon

Reputation: 84
  • View blog
  • Posts: 3,564
  • Joined: 31-March 03

Re: onChange

Posted 31 August 2007 - 06:29 AM

Is this a PHP or HTML question? Because onchange is an HTML/Javascript thing-a-ma-jig.
Was This Post Helpful? 0
  • +
  • -

#4 no2pencil  Icon User is offline

  • Admiral Fancy Pants
  • member icon

Reputation: 5363
  • View blog
  • Posts: 27,325
  • Joined: 10-May 07

Re: onChange

Posted 31 August 2007 - 06:59 AM

Don't forget at what point the execution happens.

The PHP will not be aware of the onchange event, since this takes place Client-Side & all PHP execution happens Server-Side. If you need PHP to know about the Javascript change, you'll have to parse the results back to the PHP page.
Was This Post Helpful? 0
  • +
  • -

#5 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

Re: onChange

Posted 31 August 2007 - 03:16 PM

no its on the client side... the value of total changes as the value of bQuantity changes
Was This Post Helpful? 0
  • +
  • -

#6 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

Re: onChange

Posted 01 September 2007 - 06:05 AM

still pounding through the problem... can get to change the value of total textfield even using onblur
Was This Post Helpful? 0
  • +
  • -

#7 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onChange

Posted 01 September 2007 - 06:36 AM

This is actually a Javascript issue, not PHP. As No2Pencil pointed out, unless you parse the results through the page PHP has no idea when the value of a textbox changes. DO you have any Javascript there thats detecting this? If so can you post it, if not then you need it.
Was This Post Helpful? 0
  • +
  • -

#8 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

Re: onChange

Posted 01 September 2007 - 06:43 AM

well i'm just new to both languages and based on what I understand.. the javascript i knew your trying to point out is this

<script TYPE="text/javascript">
<!--
function compute(bQuantity)
{
if (bQuantity.inchange)return;
bQuantity.inchange=true;
total.value=bQuantity.value*price.total;
total.inchange=false;
}
//-->
</SCRIPT>



am i right??
Was This Post Helpful? 0
  • +
  • -

#9 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onChange

Posted 01 September 2007 - 06:53 AM

Try this

function compute(bQuantity)
{
if (document.GetElementById(bQuantity).inchange)return;
document.GetElementById(bQuantity).inchange=true;
document.GetElementById(total).value=document.GetElementById(bQuantity).value*document.GetElementById(price).total;
document.GetElementById(total).inchange=false;
}



I'm shocked you're not getting an error with the Javascript, for you're not telling it where these form elements are.

<edit> make sure you add an ID="ElementName" to your form elements :) </edit>

This post has been edited by PsychoCoder: 01 September 2007 - 06:55 AM

Was This Post Helpful? 0
  • +
  • -

#10 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

Re: onChange

Posted 01 September 2007 - 07:04 AM

nothing the textbox total doesnt change...
Was This Post Helpful? 0
  • +
  • -

#11 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onChange

Posted 01 September 2007 - 07:09 AM

Ya know sometimes I think I'm blind, you're using inchange which doesn't exist, its actually onchange

function compute(bQuantity)
{
if (document.GetElementById(bQuantity).onchange)return;
document.GetElementById(bQuantity).onchange=true;
document.GetElementById(total).value=document.GetElementById(bQuantity).value*document.GetElementById(price).total;
document.GetElementById(total).onchange=false;
}


Was This Post Helpful? 0
  • +
  • -

#12 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

Re: onChange

Posted 01 September 2007 - 07:25 AM

still nothin new

im going to submit again codes.. i save it as buy.php
the function is inside the head tags
<script TYPE="text/javascript">
<!--
function compute(bQuantity)
{
if (document.GetElementById(bQuantity).onchange)return;
document.GetElementById(bQuantity).onchange=true;
document.GetElementById(total).value=document.GetElementById(bQuantity).value*document.GetElementById(price).total;
document.GetElementById(total).onchange=false;
}
}
//-->
</SCRIPT>



and the textboxes involved are the following..
 </tr>
									  <tr>
										<td height="30"><input name="price" type="text" id="price" value="<?echo "$price" ?>"></td>
									  </tr>
									  <tr>
										<td height="30"><input name="quantity" type="text" id="quantity" value="<?echo "$quantity" ?>"></td>
									  </tr>
									  <tr>
										<td height="30"><input name="bQuantity" type="text" id="bQuantity" value="<?echo "$bQuantity" ?>"></td>
									  </tr>
									  <tr>
										<td height="30"><input name="total" type="text" id="total" onchange="compute(this)" disabled></td>
									  </tr>


Was This Post Helpful? 0
  • +
  • -

#13 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onChange

Posted 01 September 2007 - 07:43 AM

You aren't calling the Javascript function in your textbox, try this

<script TYPE="text/javascript">
<!--
function compute(bQuantity)
{
if (document.GetElementById(bQuantity).onchange)return;
document.GetElementById(bQuantity).onchange=true;
document.GetElementById(total).value=document.GetElementById(bQuantity).value*document.GetElementById(price).total;
document.GetElementById(total).onchange=false;
}
}
//-->
</SCRIPT>



<input name="bQuantity" onchange="compute(this);" type="text" id="bQuantity" value="<?echo "$bQuantity" ?>"><



Now if theres any errors in your Javascript at least you'll know it and can go from there.
Was This Post Helpful? 0
  • +
  • -

#14 antiturncoat  Icon User is offline

  • D.I.C Head

Reputation: 0
  • View blog
  • Posts: 99
  • Joined: 08-August 07

Re: onChange

Posted 01 September 2007 - 07:50 AM

no error.. i tried surfing around the net but the onchange event is handled only in the same textbox that you changed. I knew this is possible cause i saw something similar to this concept... Does the code lacks something.. Do I have to install something or its on the browser.. I am using Firefox 2.0 and I'm coding using dreamweaver mx

This post has been edited by antiturncoat: 01 September 2007 - 07:57 AM

Was This Post Helpful? 0
  • +
  • -

#15 PsychoCoder  Icon User is offline

  • Google.Sucks.Init(true);
  • member icon

Reputation: 1641
  • View blog
  • Posts: 19,853
  • Joined: 26-July 07

Re: onChange

Posted 01 September 2007 - 07:59 AM

Open up your Error Console in Firefox Tools > Error Console then watch what happens when you tab out of the bQuantity textbox. FF isn't like IE when it comes to displaying Javascript errors.
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2