469,635 Members | 2,390 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,635 developers. It's quick & easy.

change content of div when the value input field is changed

194 100+
Hi everybody,

I have some problem so need some help. wat im trying to do is making a function which will change the value of a input field when the value of other input field is changed. im using onchage event which triggers when i left the input field which is ok.

im using PHP to get the values into the input fields:
Expand|Select|Wrap|Line Numbers
  1. <?php 
  2.  if($_POST['cbl']<>""){
  3. extract($_POST);              
  4. foreach($_POST['cbl'] as $k => $c){
  5. $k=str_replace("'","",$k);
  6. $k=str_replace("\\","",$k);
  7. $sql = "SELECT * FROM ".$GLOBALS['pre_tbl']."sometable WHERE id=".$k;
  8. $getAuto = mysql_query($sql); 
  9. $getAutoResultView = mysql_fetch_array($getAuto);
  10. $membal = soemfunction($getAutoResultView['id']);
  11. mysql_query($sql) OR die ("The query:<br>" . $sql . "<br>Caused the following error:<br>" . mysql_error());
  12.             ?>
  13.           <tr class="BalanceCells" onmouseover="style.backgroundColor='#f7f7f7';" onmouseout="style.backgroundColor='#dfdfdf';">
  14.             <td class="BalanceCells">
  15.             <input type="hidden" name="autoview['<?php echo $getAutoResultView['id']; ?>']" value="<?php echo $getAutoResultView['id']; ?>"  id="autoview">
  16.            <?= $getAutoResultView['id'] ?></td>
  17.             <td class="BalanceCells"><?= $getAutoResultView['name'] ?></td>
  18.             <td class="BalanceCells">
  19.              <?= $getAutoResultView['ba'] ?></td>
  20.             <td class="BalanceCells"><?= $getAutoResultView['no'] ?></td>
  21.             <td class="BalanceCells"><?= $CurrencySymbol.number_format($getAutoResultView['dwee'],2) ?></td>
  22.             <div id="bal-<?= $getAutoResultView['id']; ?>"><?= $membal['dwl'] ?></div>
  23.             <td class="BalanceCells"><input name="ded<?= $getAutoResultView['id']; ?>" type="text" value="<?= number_format($membal['we'],2) ?>" id="mytext-<?= echo $getAutoResultView['id']; ?>" onchange="checkChange(<?= echo $getAutoResultView['id']; ?>, this.value)" /></td>
  24.           </tr>
  25.  
  26.           <?php 
  27.           } 
  28.           }?>
  29.  
im trying to make function when i change the value of input field name ded then checkChange function will be called and it will change the value inside div anmed bal-some id(which will be generated dynamically through php). im not very much expert with the javascript but i made some function which is not giving me the value which falls inside the div. and can i use document.getElementById('name'+id).value?? or something else. im using the following code:

Expand|Select|Wrap|Line Numbers
  1.  
  2. function checkChange(id,value){
  3. var a = document.getElementById('bal'+id);
  4. alert(a);
  5. }
  6.  
  7.  
Please ignore any php error cuz its working fine with me.
now this funciton says a is null. please help me. thanx
Mar 27 '10 #1
4 5716
RamananKalirajan
607 512MB
Hi,
Please check this line.
Expand|Select|Wrap|Line Numbers
  1. <div id="bal-<?= $getAutoResultView['id']; ?>">
there is a '-' after the string 'bal'

Thanks and Regards
Ramanan Kalirajan
Mar 27 '10 #2
mfaisalwarraich
194 100+
thanx for ur quick reply. but it has now something [object HTMLDivElement] means its working. but the problem is same as im not able to get the content of the div.
Mar 27 '10 #3
Dormilich
8,652 Expert Mod 8TB
document.getElementById() returns a reference to the DOM-Element. getting the content actually depends on what’s inside the div. you can use .textContent (all the text in the div), .innerHTML (the HTML code in the div), .firstChild.data (text of the first node (… if it’s a text node)), etc.
Mar 27 '10 #4
mfaisalwarraich
194 100+
thanx dormilich for your help.
Mar 30 '10 #5

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

4 posts views Thread by Richard Cornford | last post: by
5 posts views Thread by =?Utf-8?B?Y2hlY2tyYWlzZXJAY29tbXVuaXR5Lm5vc3BhbQ== | last post: by
reply views Thread by gheharukoh7 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.