Web Development
 
Your Ad Here
Ajax calls using prototype 
Protoype is an excellent javascript framework that provides an easy way to make ajax calls.

Here is the sample code of how to make the call:

//first I am passing a variable that I call id, this would be the row id for the database table being used, for example: if I'm updating the record with the id of 4, I would call: javascript:dosomethingAjax('4');
//the id is passed to the file dosome.php that will handle whatever it is you are trying to do
//if you want to pass more variables through the ajax call you would use commas to separate them, for example: parameters: {u: id, name: 'John', age: 24}

function dosomethingAjax(id) {
var myAjax = new Ajax.Request('dosome.php',
{method: 'get', parameters: {u: id},
onComplete: handleResponse});
}
//once dosome.php gets processed, the ajax call is complete and the following function is called, in this case, I am putting the results inside a div with the id of displayResults
function handleResponse(transport) {
document.getElementById('displayResults').innerHTML = transport.responseText;
}

//here is how to setup the dosome.php

<?php
//the variable u is being passed by the ajax call listed above
$id = $_GET['u'];
//do something like update or insert or select
echo "Success!";
?>

[ add comment ] ( 23 views )   |  permalink  |  related link  |   ( 3 / 190 )
Form Select State & Show current selection 
In this very basic example, the form is going to the same page on submit, assigning the state value to a session and showing the current selection in the drop down.

<?php
$_SESSION['STATE'] = $_POST['STATE'];

$temp_st = "type".$_SESSION['STATE'];
$$temp_st = " selected";
?>

<form name="form" method="post" action="">
<select name="STATE" id="STATE"
<option value="AL"<?php echo $typeAL; ?>>Alabama</option>
<option value="AK"<?php echo $typeAK; ?>>Alaska</option>
<option value="AZ"<?php echo $typeAZ; ?>>Arizona</option>
<option value="AR"<?php echo $typeAR; ?>>Arkansas</option>
<option value="CA"<?php echo $typeCA; ?>>California</option>
<option value="CO"<?php echo $typeCO; ?>>Colorado</option>
<option value="CT"<?php echo $typeCT; ?>>Connecticut</option>
<option value="DE"<?php echo $typeDE; ?>>Delaware</option>
<option value="DC"<?php echo $typeDC; ?>>District of Columbia</option>
<option value="FL"<?php echo $typeFL; ?>>Florida</option>
<option value="GA"<?php echo $typeGA; ?>>Georgia</option>
<option value="HI"<?php echo $typeHI; ?>>Hawaii</option>
<option value="ID"<?php echo $typeID; ?>>Idaho</option>
<option value="IL"<?php echo $typeIL; ?>>Illinois</option>
<option value="IN"<?php echo $typeIN; ?>>Indiana</option>
<option value="IA"<?php echo $typeIA; ?>>Iowa</option>
<option value="KS"<?php echo $typeKS; ?>>Kansas</option>
<option value="KY"<?php echo $typeKY; ?>>Kentucky</option>
<option value="LA"<?php echo $typeLA; ?>>Louisiana</option>
<option value="ME"<?php echo $typeME; ?>>Maine</option>
<option value="MD"<?php echo $typeMD; ?>>Maryland</option>
<option value="MA"<?php echo $typeMA; ?>>Massachusetts</option>
<option value="MI"<?php echo $typeMI; ?>>Michigan</option>
<option value="MN"<?php echo $typeMN; ?>>Minnesota</option>
<option value="MS"<?php echo $typeMS; ?>>Mississippi</option>
<option value="MO"<?php echo $typeMO; ?>>Missouri</option>
<option value="MT"<?php echo $typeMT; ?>>Montana</option>
<option value="NE"<?php echo $typeNE; ?>>Nebraska</option>
<option value="NV"<?php echo $typeNV; ?>>Nevada</option>
<option value="NH"<?php echo $typeNH; ?>>New Hampshire</option>
<option value="NJ"<?php echo $typeNJ; ?>>New Jersey</option>
<option value="NM"<?php echo $typeNM; ?>>New Mexico</option>
<option value="NY"<?php echo $typeNY; ?>>New York</option>
<option value="NC"<?php echo $typeNC; ?>>North Carolina</option>
<option value="ND"<?php echo $typeND; ?>>North Dakota</option>
<option value="OH"<?php echo $typeOH; ?>>Ohio</option>
<option value="OK"<?php echo $typeOK; ?>>Oklahoma</option>
<option value="OR"<?php echo $typeOR; ?>>Oregon</option>
<option value="PA"<?php echo $typePA; ?>>Pennsylvania</option>
<option value="RI"<?php echo $typeRI; ?>>Rhode Island</option>
<option value="SC"<?php echo $typeSC; ?>>South Carolina</option>
<option value="SD"<?php echo $typeSD; ?>>South Dakota</option>
<option value="TN"<?php echo $typeTN; ?>>Tennessee</option>
<option value="TX"<?php echo $typeTX; ?>>Texas</option>
<option value="UT"<?php echo $typeUT; ?>>Utah</option>
<option value="VT"<?php echo $typeVT; ?>>Vermont</option>
<option value="VA"<?php echo $typeVA; ?>>Virginia</option>
<option value="WA"<?php echo $typeWA; ?>>Washington</option>
<option value="WV"<?php echo $typeWV; ?>>West Virginia</option>
<option value="WI"<?php echo $typeWI; ?>>Wisconsin</option>
<option value="WY"<?php echo $typeWY; ?>>Wyoming</option>
</select>
<input type="submit" name="Submit" value="Submit"/>
</form>

[ 3 comments ] ( 17 views )   |  permalink  |   ( 3 / 237 )
Validating numbers 
var digits="0123456789"
var temp


if (form.SSN3.value=="") {
alert("Please enter your Social Security Number.")
form.SSN3.focus();
return false;
}
for (var i=0;i<form.SSN3.value.length;i++){
temp=form.SSN3.value.substring(i,i+1)
if (digits.indexOf(temp)==-1){
alert("Only numbers are accepted in Social Security Number.")
form.SSN3.focus();
return false;
}
}


[ 1 comment ] ( 9 views )   |  permalink  |   ( 2.9 / 234 )
Date drop down for PHP forms 
// created by www.dpwebservices.net

function listbox_day ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($dayf=01;$dayf<=31;$dayf++) {
if ($default == $dayf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(d, mktime(0,0,0,0,$dayf,2000))."\" $selected class=\"field\">".date(j, mktime(0,0,0,0,$dayf,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_month ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($monthf=01;$monthf<=12;$monthf++) {
if ($default == $monthf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(m, mktime(0,0,0,$monthf,1,2000))."\" $selected class=\"field\">".date(M, mktime(0,0,0,$monthf,1,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_year ($name, $start, $end, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($yearf=$end;$yearf>=$start;$yearf--) {
if ($default == $yearf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"$yearf\" $selected class=\"field\">$yearf</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_hour ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($hourf=1;$hourf<=12;$hourf++) {
if ($default == $hourf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(h, mktime($hourf,0,0,0,0,2000))."\" $selected>".date(g, mktime($hourf,0,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_24hour ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($hourf=00;$hourf<=23;$hourf++) {
if ($default == $hourf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(H, mktime($hourf,0,0,0,0,2000))."\" $selected>".date(H, mktime($hourf,0,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_min ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($minf=00;$minf<=59;$minf++) {
if ($default == $minf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".date(i, mktime(0,$minf,0,0,0,2000))."\" $selected>".date(i, mktime(0,$minf,0,0,0,2000))."</option>\n";
}
$result.="</select>\n";
return $result;
}

function listbox_week ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
$weekx = '0';
for ($week_count=strftime("%U"); $week_count>=1; $week_count--) {
$weekx ++;
$str = '-'.$week_count.' week Monday';
if (($timestamp = strtotime($str)) === -1) {
$weekmsg = "The string ($str) is bogus";
} else {

$weekmsg = "Week ".$weekx." - ".date('F j',$timestamp);
$weekdate = date(m.'/'.d.'/'.y,$timestamp);

}
// echo $default; weekx to select the week
if ($default == $weekdate) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".$weekdate."\" $selected>".$weekmsg."</option>\n";
}
$result.="</select>\n";
return $result;
}

// onChange=\"MM_goToURL('parent','#');return document.MM_returnValue\"

function listbox_nummon ($name, $default=0) {
$result="<select name=\"$name\" size=1 class=\"submit\">\n";
for ($dayf=1;$dayf<=48;$dayf++) {
if ($default == $dayf) {$selected="selected";} else {$selected="";}
$result.="<option value=\"".$dayf."\" $selected>".$dayf."</option>\n";
}
$result.="</select>\n";
return $result;
}

/*
example of echos


<?php echo listbox_month("month", 7); ?> /
<?php echo listbox_day("day",23); ?> /
<?php echo listbox_year("year", 1994, 2003, 2001); ?>,&nbsp;
<?php echo listbox_hour("hour", 12); ?>:
<?php echo listbox_min("min", 00); ?>
);
<br>
<?php echo listbox_month("month2", 1); ?> /
<?php echo listbox_day("day2", 2); ?> /
<?php echo listbox_year("year2", 1994, date(Y), 2002); ?>,&nbsp;
<?php echo listbox_hour("hour2", 11); ?>:
<?php echo listbox_min("min2", 59); ?>

Below is to call the current "week - month day" back to week 1 in a pulldown menu...
echo listbox_week("week", strftime("%U"));

*/


[ add comment ] ( 7 views )   |  permalink  |   ( 3 / 185 )
Select between two dates 
A few hints when dealing with "between date" searches, these are corrections to oracle manuals that don't tell you to handle this properly:

SELECT *
FROM
Your Table
WHERE
DTM_COLUMN BETWEEN TO_DATE('03-01-2006', 'MM-DD-YYYY') AND TO_DATE('03-17-2006', 'MM-DD-YYYY')+1

By using the +1 you get the data between 3/01 to 3/17

Without the +1 you get the data between 3/01 to 3/16

----

Another hint, if you have any queries like the following, you best fix them before the year rolls over...

SELECT *
FROM
WHERE
TO_CHAR(DTM_COLUMN, 'MM-DD-YYYY') BETWEEN '03-01-2007' AND '03-17-2007'

The above example works fine until you change the start year to 2006...
Oracle can not search TO_CHAR unless it is within the same year...


[ add comment ] ( 5 views )   |  permalink  |   ( 2.9 / 214 )

<Back | 1 | 2 | 3 | 4 | Next> Last>>


Home | Portfolio | Hosting | Web Development | Contact Us
© 2007 dpwebservices.net. All right reserved.