Author Topic: Replacing html  (Read 431 times)

0 Members and 1 Guest are viewing this topic.

Offline wigglesbyTopic starter

  • Irregular
  • Posts: 42
    • View Profile
Replacing html
« on: February 09, 2010, 06:13:58 AM »
Hi
I have written some code, that calculates the value of one input box minus another input box and then puts the sum into another input box.

This works fine if there is only 1 row (the page uses php to loop through the db), with only 3 boxes.

If there is another table row (i.e. another 3), the code doesn't seem to update but the row below does.


<script type="text/javascript" />
   
jQuery.noConflict();

      
jQuery(document).ready(function() {

        var 
cartons2 jQuery('input#txtitemscarton<? echo $recId ?>').val();
    
	
var 
received2 jQuery('input#txtitemsreceived<? echo $recId ?>').val();
    
	
var 
remaining2 jQuery('input#txtitemsremiaining<? echo $recId ?>').val();
    
	
var 
gRemaining cartons2 received2;
    
	
var 
gReceived received2;

	
var 
html2 '<input type="text" onblur="updateReceivedCartons()" id="txtitemsremaining<? echo $recId ?>" name="txtitemsremaining<? echo $recId?>" class="teenyinput numbers" value="'+gRemaining+'" />';
    
jQuery("#txtitemsremaining<? echo $recId ?>").after(html2).remove();
    var 
html3 '<input type="text" onblur="updateRemainingCartons()" id="txtitemsreceived<? echo $recId ?>" name="txtitemsreceived<? echo $recId?>" class="teenyinput numbers" value="'+gReceived+'" />';
    
jQuery("#txtitemsreceived<? echo $recId ?>").after(html3).remove();

      });

</script>


Above is my code:

The 3 input fields have the following ids:
carton number  = txtitemscarton + the id of the row from the db
received number = txtitemsreceived + the id of the row from the db
remaining number = txtitemsremaining + the id of the row from the db

So on load, it should detect the value of txtitemscarton... - txtitemsreceived and then insert the result into txtitemsremaining, but it if there are 2 or more rows, then it only replaces 1 txtitemsreceived input box.

I have attached a screenshot of what I mean.

Any ideas how I can change this code?

Thanks



[attachment deleted by admin]

Offline crashmaster

  • Enthusiast
  • Posts: 175
  • Gender: Male
  • Nobody will be forgiven
    • View Profile
    • Czech Drum and Bass Step Dance Portal
Re: Replacing html
« Reply #1 on: February 09, 2010, 03:00:33 PM »
quite stupid idea to use PHP function oin JS.. try to avoid it..can cause TOO MANY problems..
« Last Edit: February 09, 2010, 03:01:50 PM by crashmaster »
I'll never be the same...

Offline seventheyejosh

  • Devotee
  • Posts: 633
  • i see what you did there...
    • View Profile
    • Net Worth Pro
Re: Replacing html
« Reply #2 on: February 09, 2010, 04:18:23 PM »
Regardless of proper practices, calling someone stupid is quite counter-productive...
My first iPhone app is out! Check it out -> http://networthproapp.com

Offline wigglesbyTopic starter

  • Irregular
  • Posts: 42
    • View Profile
Re: Replacing html
« Reply #3 on: February 10, 2010, 04:41:23 AM »
I haven't called a PHP function in my JS.

updateReceivedCartons() is another JS function:


<script type="text/javascript" />
   
jQuery.noConflict();

function 
updateReceivedCartons(){

	
var 
cartons jQuery('input#txtitemscarton<? echo $recId ?>').val();
	
var 
remaining jQuery('input#txtitemsremaining<? echo $recId ?>').val();
    var 
received jQuery('input#txtitemsreceived<? echo $recId ?>').val();
    var 
gTotal cartons remaining;
    var 
html '<input type="text" onblur="updateRemainingCartons()" id="txtitemsreceived<? echo $recId ?>" name="txtitemsreceived<? echo $recId?>" class="teenyinput numbers" value="'+gTotal+'" />';
     if (
gTotal 0)
     {
     
	
alert("The number you entered is too large.");

     }
	
 else
	
 {
	
	
 
jQuery("#txtitemsreceived<? echo $recId ?>").after(html).remove();

	
 }

}
</script>



<script type="text/javascript" />
   
jQuery.noConflict();

function 
updateRemainingCartons(){

	
var 
cartons3 jQuery('input#txtitemscarton<? echo $recId ?>').val();
	
var 
remaining3 jQuery('input#txtitemsremaining<? echo $recId ?>').val();
    var 
received3 jQuery('input#txtitemsreceived<? echo $recId ?>').val();
    var 
gTotal2 cartons3 received3;
    var 
html '<input type="text" onblur="updateReceivedCartons()" id="txtitemsremaining<? echo $recId ?>" name="txtitemsremaining<? echo $recId?>" class="teenyinput numbers" value="'+gTotal2+'" />';
     if (
gTotal2 0)
     {
     
	
alert("The number you entered is too large.");

     }
	
 else
	
 {
	
	
 
jQuery("#txtitemsremaining<? echo $recId ?>").after(html).remove();

	
 }

}
</script>


Thanks