Jump to content

[SOLVED] understanding how avascript innerHTML works in a php generated table


warewolfe

Recommended Posts

Hi, I'm new to javascript and trying to get this thing up and running as a glorified hello world script.

The testfunction works as expected but I can't seem to get the innerHTML of the table. Anybody know whats up?

 

<?php
/*
  * This functions just provides a simple id name for
  * each cell. It could probably have been done easier
  */

  function getCellID($ii,$jj)
  {
   $answer= 'c'.$ii.$jj;
   return $answer;
  }

/*
  * This function gives the table a cross hatch look
  */
function sortTDType($ii,$jj)
{
  $answer="tdp";
  if($jj>=3 && $jj<=5)
  {
   $answer="tdh";
  }
  else if($ii >= 3 && $ii <=5)
  {
   $answer="tdh";
  }

  if(($ii >= 3 && $ii<=5)&& ($jj >= 3 && $jj <= 5))
  {
   $answer="tdp";
  }
  return $answer;
}
?>

<html>
<head>
  <title>Sodoku Solver Prototype seven</title>
<link rel="stylesheet" type="text/css" href="prototype7.css" />
<script language = "JavaScript" type="text/javascript">
<!--
function validCheck(var1,var2)
{
  var answer=true;
  var vector='c'+var1+var2; 
  var vectorValue =document.getElementById(vector).value;
  //column check
  for(var ii=0;ii<=8;ii++)
  {
   var checkCount=ii+1;
   var testVector='c'+ii+var2;
   var testVectorValue = document.getElementById(testVector).value;
   /*
   alert('check ' + checkCount + 
         ' : vector '+ vector+ '= ' + vectorValue + 
 ' : testVector ' +testVector +'= ' + testVectorValue);
    */
   if(vectorValue==testVectorValue && vector != testVector && vectorValue!=0)
   {
   alert('You Can not put that there, clash on column!');
    answer=false;
    break;
   }
  }//end for loop
  //row check
  for(var ii=0;ii<=8;ii++)
  {
   var checkCount=ii+1;
   var testVector='c'+var1+ii; 
   var testVectorValue = document.getElementById(testVector).value;
   /*
   alert('check ' + checkCount + 
         ' : vector '+ vector+ '= ' + vectorValue + 
 ' : testVector ' +testVector +'= ' + testVectorValue);
    */
   if(vectorValue==testVectorValue && vector != testVector && vectorValue!=0)
   {
    alert('You can not put that there, clash on the row');
    answer=false;
    break;
   }
  }//end for loop
  
return answer;
}//end function validCheck

function resetField(var1,var2)
{
  var vid='c'+var1+var2;
  document.getElementById(vid).innerHTML ='0'; 
}


function validEntry(var1,var2)
{  
  var vector='c'+var1+var2;
  var orginal= document.getElementById(vector).value;
  if(!validCheck(var1,var2))
  {
   alert('Not working, try again');
   resetField(var1,var2);
  }
}

//-->
</script>
</head>
<body>
  <h1>Prototype 7:Intial Form Side</h1>
   <h2>Input the initial sodoku form</h2>
  <form action="Prototype7Script.php" method="post">
  <table class="displayTable">
  <?php
  for($ii=0;$ii<=8;$ii++)
  {
   echo"<tr>";
   for($jj=0;$jj<=8;$jj++)
   {
    $cellID=getCellID($ii,$jj);
      $tdtype=sortTDType($ii,$jj);
      echo"<td>
<input
         class=\"$tdtype\"
         type=\"text\"
      	 value=\"0\"
 size=\"1\"
         maxlength=\"1\"
         id=\"$cellID\"
 name=\"data[$ii][]\"
 onblur=\"validEntry($ii,$jj)\"
/> 
</td>"; 
   }
   echo"</tr>";
  }
  ?>
   </table>
  <input type="submit" value="submit"> 
  
  </form>

  <script type="text/javascript">
     
   function testText()
   {
     document.getElementById('testID').innerHTML = 'zzzz';
   }

   </script>
   
   <p>Another <b id='testID'>test</b></p>
   <input type='button' onclick='testText()'  value='tester button' />
  
</body>
</html>

Link to comment
Share on other sites

Just had a D'oh moment.

 

  To clarify for any interested,

 

For some reason, I don't understand just yet, if I want to change the something the page displays outside of a table I use;

document.getElementById.innerHTML = "some value";

 

but inside of a table <td> tag I need to use;

 

document.getElementById.value="some value";

 

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.