abdfahim Posted January 13, 2009 Share Posted January 13, 2009 Hi, I have 13 buttons and I have used innerhtml to write different thing inside a div depending on which button I click. <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function secAdetails(q){ document.getElementById('secA').innerHTML = ''; //SecA is the DIV ID alert(myArray[q]); document.getElementById('secA').innerHTML = myArray[q]; } // End --> </script> The javascript array myArray[q] has all the strings stored (so, array lenghth is 13). Now its behaving piculiarly. For example, if I click on Button 7 (which has the largest string to display), it is showing partial text. Also, if I 1st select Button 1 and then Button 7, it always shows first 4 lines, if I choose Button 2 and then Button 7, it always shows first 7 lines etc. Anybody has any idea why this is happening? Btw, I put an alert and in the alert dialog box, it shows wwhole string, just it can't write that completely using innerhtml! Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 13, 2009 Share Posted January 13, 2009 what are the strings? Quote Link to comment Share on other sites More sharing options...
abdfahim Posted January 13, 2009 Author Share Posted January 13, 2009 Strings are normal text with some html tags. For example, one string is var mystr='<b><u>Roberto</u> : </b><br>questions should be more practical.<br><br><b><u>This is another name</u> : </b><br>Here is another text.<br><br><b><u>'; like this. Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 13, 2009 Share Posted January 13, 2009 this works fine for me: <SCRIPT LANGUAGE="JavaScript"> <!-- Begin myArray = [ '<b><u>Roberto</u> : </b><br>questions should be more practical.<br><br><b><u>This is another name</u> : </b><br>Here is another text.<br><br><b><u>', 'Here is another string' ]; function secAdetails(q){ document.getElementById('secA').innerHTML = ''; //SecA is the DIV ID alert(myArray[q]); document.getElementById('secA').innerHTML = myArray[q]; } // End --> </script> <input type="button" value="Button 1" onclick="secAdetails(0);" /> <input type="button" value="Button 2" onclick="secAdetails(1);" /> <div id="secA"></div> can you post a snippet of code that doesn't work for you...that way i can see what you see Quote Link to comment Share on other sites More sharing options...
abdfahim Posted January 14, 2009 Author Share Posted January 14, 2009 Hi, I was wondering if I have some problem in my coding, why would it act pseudo-random way. Like, the amount of text its displaying depends on what I click before clicking this button. If I click button A and then the concern button, it always shows certain amount of text, if I click button B and then the concern button, it always shows another amount of text. But this amount is constant. I mean if my sequence is ButtonA, then concern button, it always shows same amount of text, though its partial. Anyway, here is my code. <?php include("config.php"); echo "<HTML><HEAD> <TITLE></TITLE>"; ?> <SCRIPT LANGUAGE="JavaScript"> var myArray = new Array(); </SCRIPT> <?php echo "</HEAD><BODY>"; for($m=0;$m<13;$m++){ echo "<a style=\"cursor: hand;\" onclick=\"javascript: secAdetails(".$m.");\">Q".($m+1)."</a><BR>"; } echo "<div id=\"secA\" style=\"text-align:left; overflow: auto; width: 98%;\">"; echo "</div>"; for($x=0;$x<13;$x++){ $myquery="Select username, q".$x."_comm as com from plan_survey"; $result=mysql_query($myquery) or die(mysql_error()); if(mysql_num_rows($result)>0){ while($row=mysql_fetch_assoc($result)){ if(!get_magic_quotes_gpc()) { $name = addslashes($row['name']); $com = addslashes($row['com']); }else{ $name = $row['name']; $com = $row['com']; } $com=str_replace("\r\n","",$com); $com=str_replace("\n","",$com); $temp = "<b><u>".$name."</u> : </b><br>".$com."<br><br>"; //echo $temp; echo "<SCRIPT LANGUAGE=\"JavaScript\">myArray[".$x."]='".$temp."';</SCRIPT>"; } } mysql_free_result($res1); } ?> <SCRIPT LANGUAGE="JavaScript"> <!-- Begin function secAdetails(q){ alert(q); document.getElementById('secA').innerHTML += myArray[q]; } // End --> </script> <?php echo "</BODY></HTML>"; ?> Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 14, 2009 Share Posted January 14, 2009 hey, can you post a dump of the table? just the CREATE TABLE command and some INSERTS so I can test your code. looking at it, nothing jumps out as being wrong, but i can't test it either Quote Link to comment Share on other sites More sharing options...
rhodesa Posted January 14, 2009 Share Posted January 14, 2009 i looked it over again, and there was some stuff i found...try this out: <?php include("config.php"); $links = array(); $data = array(); for($x=0;$x < 13;$x++){ $query = "SELECT username, q".$x."_comm AS COM FROM plan_survey"; $result = mysql_query($query) or die(mysql_error()); if(mysql_num_rows($result) > 0){ while($row=mysql_fetch_assoc($result)){ $data[] = sprintf('<b><u>%s</u> : </b><br>%s<br><br>',htmlspecialchars($row['name']),htmlspecialchars($row['com'])); } } $links[] = sprintf('<a style="cursor:hand;" onclick="secAdetails(%s);">Q%s</a><br />',$x,$x+1); mysql_free_result($result); } ?> <html> <head> <title></title> <script type="text/javascript"> <!-- Begin var myArray = <?php echo json_encode($data); ?>; function secAdetails(q){ alert(q); document.getElementById('secA').innerHTML += myArray[q]; } // End --> </script> </head> <body> <?php echo implode("\n",$links); ?> <div id="secA" style="text-align:left;overflow:auto;width:98%;"></div> </body> </html> Quote Link to comment Share on other sites More sharing options...
abdfahim Posted January 15, 2009 Author Share Posted January 15, 2009 hey rhodesa, sorry i was out of the town so i m late in reply. anyway, it'll be better if you say exactly where in the code you are suspecting the problem. then i'll change there. I can't exactly copy ur code because the code i post is just a portion of my full code. coz, otherwise it would be so large that you might fill disgusted. And I will paste the table with some data at the earliest possible time. Thanks for ur help. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.