OMIS 120 Cheat Sheet

A Programming › JavaScript cheat sheet in English by bossross333
9,544 views 4,178 downloads 9 Jun 2015 History
3.7 avg · 0 ratings

HTML

<link href =”layout.css” rel=”stylesheet” type=”text/css”>
<form action ="test.php" method="get">
<input type="text" id="tester">
<input type="submit" id="submit" value="submit">

<img src="name" align="left"> Aligns an image: left

input types="radio,"checkbox"
<select name="xyz">
<option value="jerry">Jerry</option>

HTML 2

<div id="­tes­t">
for CSS #test{­col­or:­#fff}
<div class=­"­tes­t">
for CSS .test{}
<ol­></­ol>
Creates a numbered list
<ul­></­ul>
Creates a bulleted list
<li­></­li>
Precedes each list item, and adds a number or symbol depending upon the type of list selected

CSS

CSS

HTML/CSS example

<h1>Baby Geneva's Web Page</h1><div id="notice">    <img src="geneva.jpg" alt="Geneva" />    What is your name?     <span class="notice"> (I am Geneva!)</span></div><p class="notice">I <br /> am <br /> 15 <br /> months <br /> old</p><p class="notice">    My <br /> favorite <br /> toy <br /> is <br /> your <br /> cell phone </p><h2>(written by Geneva, May 2008)</h2>

HTML/CSS example

CSS
h1 {     text-align: center;     border: 2px solid black; } #notice .notice {     text-decoration: underline; } p.notice {     border: 2px solid black;     float: right;     width: 10%; } h2 { clear: both; } h2, #notice {     border-top: 1px dashed black;     border-bottom: 1px dashed black; }

MySQL

LIKE,ORDER BY, LIMIT, INSERT, UPDATE, DELETE, INSERT INTO table_­nam­e(c­olumn1) VALUES­(va­lue1);

PHP(SQL)

// Create connection
    $dbhandle = mysql_connect($hostname, $username, $password) or die("Unable to connect to MySQL"); 

//database select
    $db_select = mysql_select_db("$db_name", $dbhandle) or die("Cannot      connect to database"); 

    $JuiceID = $_POST['JuiceID'];
    $Attributes = $_POST['Attributes'];
    $attValue = $_POST['attIn'];

if($sql = "SELECT * FROM Juices WHERE JuiceID=$JuiceID"){
      $result = mysql_query($sql);        }

while($row = mysql_fetch_array($result, MYSQL_ASSOC)) { 
       print " ".$row["JuiceID"]." ".$row["JuiceBrand"]." "; 
}

PHP q4

<?php $letter=strtolower($_GET[ "letter"]); 
$times=( int) $_GET[ "times"]; 
$matches=0; 
foreach (file( "peeps.txt", FILE_IGNORE_NEW_LINES) as $line) { $lowerline=strtolower($line); 
$count=0 ; 
for ($i=0 ; $i < strlen($line); $i++) { 
$ch=$ lowerline[$i];
 if ($ch==$ letter) { 
$count++; } } 
if ($count>= $times) { $matches++; ?>
<p><strong><?= $line ?></strong>
contains '
    <?=$ letter ?>' exactly
        <?=$ times ?>times.</p>
<?php } } if ($matches==0 ) { ?>
<p>No names contained '
    <?=$ letter ?>' enough times.</p>
<?php } ?>

PHP mid_q3

$babyName=$_GET["name"]; 
$lines = file("names.txt"); 
$output=-1; //default value
for($i=0; $i<count($lines); $i++){ 
 $line = $lines[$i];  
$tokens = explode(" ", $line); 
if(strtolower($babyName)==strtolower($tokens[0])){  $output=$tokens[1];   
for($j=2; $j<count($tokens); $j++){   
 if((int)$output>(int)$tokens[$j]){   
  $output=$tokens[$j];   
 }   }  } }
 print $output; 

#getmo­viename

#get movie name
$movie=$_REQUEST['movie'];
$filePath="moviefiles/".$movie."info.txt";
list($movieName,$year,$score)=file($filePath);
print"<h1> $movieName ($year) </h1>";
#add a line to a file
$new_txt="hello there";
file_put_contents("poem.txt", $new_txt, FILE_AMMEND);

PhP String functions

var str= "abcd,efgh";
var a=str.length;//gets 9
var b=str.substring(1,3);//gets "bc"
var c=str.indexOf('b');//gets 1
var d=str.toUpperCase();//gets "ABCD,EFGH"
var e=str.charAt(2);//gets "c"
var f=str.split(",");
//gets array ("abcd,"efgh")

JavaScript divide function

window.onload = function() {
document.getElementById("del").onclick = divideAll;
};

function divideAll() {
var divisor = document.getElementById ("divisor").value;
var div = document.getElementById ("buttons");
var buttons = div.getElementsByTagName("button");
for (var i = 0; i < buttons.length; i++) {
var number = buttons[i].innerHTML;
   if (number % divisor == 0) {
div.removeChild(buttons[i]);
i--;}}}

JavaScript ex

<script LANGUAGE="JavaScript" type="text/javascript">
function yearConvert (form){
form.dYears.value = form.hYears.value*7;
}
</script>

<input TYPE="button" VALUE="change color" ONCLICK="document.body.style.backgroundColor = '#' + Math.random().toString(16).slice(2,8);">
<INPUT TYPE ="text" NAME="hYears" SIZE=10>
<INPUT TYPE ="button" VALUE="Calculate" ONCLICK="yearConvert(this.form)">

JavaScript guess rand

<script LANGUAGE="JavaScript" type="text/javascript">
var randnum = Math.floor(Math.random() * 10) + 1; //Generate random number
var count = 0;
function Guess() {
var x = document.resultform.guess.value;count++;
status = "Tries: " + count;
	if (x < randnum) {
    		document.resultform.tip.value = "Too low!";}
    
	if (x > randnum)
    		document.resultform.tip.value = "Too high!";
 
	if (x == randnum) {
  		document.resultform.tip.value = "You got it right in " + count + " tries!";}    
    	document.getElementById('total').innerHTML = + x;}
</script>

parent­-child script

<div id="div1">
<p id="p1">This is words</p>
<p id="p2">This is more words</p>
</div>

var para=document.creatElement("p");
var node=document.createTextNode("This is new");
para.appendChild(node);
var parent=document.getElementById("div1");
var child=document.getElementById("p1");
parent.replaceChild(para,child);

Badges

Good Cheat Sheet Nice Cheat Sheet Downloaded from Unusual Locations × 1

Comments

No comments yet.

Cheatography n. The art of mapping complex subjects into clear, instantly navigable reference guides.