Jump to content

warewolfe

Members
  • Posts

    57
  • Joined

  • Last visited

    Never

Posts posted by warewolfe

  1. function checkInput($string)
    {
      return preg_match('/^[a-z0-9\s]*$/i', $string);
    }
    

    This will accept letters, number and spaces. If you want full stops and other punctuation just escape the character and add within the square brackets. eg [a-z09\s\.] will let people add a full stop at the end of a sentence.

  2. hi, a hint for working in both FF and IE is to have

    *{

    padding:0;

    margin:0;

    }

    at the start of your css file.

    some of the problem with ie/ff incompatibility is that ie and ff have different default widths for both margins and padding. This code will turn them all off and make you set everything manually.

     

    #side-menu img

    {

    border-width:0;

    }

    should get rid of the border line in both ie and ff

  3. it depends on what the function is suppose to do and how complex a system the function is a part of.

     

      If the function is simple and its purpose is to generate atomic html then use echo.

    ie, if you want to print "hello world" then use echo.

     

    If the function is part of more complex system like database systems, Object oriented, and/or implementing the MVC (Model View Controller) architectural pattern then use returns.

    ie, complexSQLQuery( param1, param2,param3,param 4)

        {

            //complext code here

            return answer

          }

     

  4. You just use the html image tag with an absolute tag.

     

    <img src="http://www.whateversite.com/images/some.imagtag" />

     

      This is considered rude when you do it without asking. And they could change the image to whatever they want without you realising it.

  5. Friendly advice.

     

    change the requires to includes and remove the error suppression symbol @ from the start of the lines while you are writing your script so you can see what is going wrong.

     

    Also, if you are using apache (I don't know how IIS or other servers do it) then go to the apache logs and check out the last few entries in the error log.

  6. change

    var myTextareaValue = textareaValue.replace('\n','<br/ >');

     

    to

     

    var myTextareaValue = myTextareaValue.replace(/\n/g, /<b r>/ );

     

     

    The g switch makes the changes global.

    I'm not certain if you can escape the forward slash in the <b r /> replacement section

    but if you can it'll probably look like /<br \/>/

    I added a space in the br to stop the line from breaking

  7. Just some general ideas, first I don't know just how long your arrays will be so it may be a good idea to sort both arrays with. It may not matter.

     

      array1.sort;

      array2.sort;

     

    then nest some for loops for comparison.

     

    function arrayCompare(array1, array2)

    {

    var answer=false;

    for(var ii = 0;ii<array1.length;ii++)

    {

      var target=array1[ii];

      for(var jj=0;jj<array2.length;jj++)

      {

      var comparison=array2[jj];

      if(target == comparison)

      {

        array1.shift();//remove matching elements from the first array.

        break;// and get out of the loop.

      }   

      }//end jj for loop

    }//end ii for loop

     

    // if after removing all the matching elements in the first array

    // the array length is zero then you've got a match.

    if(array1.length <1)

    {

      answer = true;

    }

    return answer;

    }//end arrayCompare

     

    Caveat

     

    Please note I haven't actually tried this as I'm about to head to bed.

     

    I don't know if you've considered what happens with multiple instances of numbers.

     

    This will destroy the first array, if you want to keep it, send the function a copy of the original.

     

  8. 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>
    

  9. Hi, I know this is phpfreaks but javascript would probably be your best bet with this sort of problem and using alert boxes to warn/inform the user.

     

    Add this script in the head section of your page.

     

    <script language="javascript" type="text/javascript">

      function warning()

      {

        if(criticalInformationCheck())

        {

        alert("Warning! Warning! Warning!, you might want to change warning to something useful");

        }

     

        function criticalInformationCheck()

        {

          var answer = true;

          //how this will work will depend on the DOM of the page you are generating.

          //eg if div exist then anwer is false

          // or if div is empty then answer is false

          return answer;

        }

      }

    </script>

     

    and add this to the body tag

    <body onload="warning()">

     

     

     

×
×
  • 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.