471,852 Members | 908 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,852 software developers and data experts.

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>
  26.           <?php 
  27.           } 
  28.           }?>
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
  2. function checkChange(id,value){
  3. var a = document.getElementById('bal'+id);
  4. alert(a);
  5. }
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 5759
608 512MB
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
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
8,658 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
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 NeoPa | last post: by
reply views Thread by YellowAndGreen | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.