Monthly Archives: December 2009

Javascript jump box

Sometime you want to automatically do something when people selecting an option from a combo box. Here is the HTML + js code

1
2
3
4
5
6
7
<form name="form">
<select name="mybox" onchange="window.location.href=this.options[this.selectedIndex].value;">
     <option selected>Please Select
     <option value="http://www.example.com/">example site
     <option value="http://www.google.com/">google site
</select>
</form>

If want to open it in new window just change the window.location.href to window.open(xxx)

How to handle checkbox in PHP

Check box handling is bit different compared to other form objects because it can receive multiple values. Here is the HTML code for the form

1
2
<input name="fruit[]" type="checkbox" value="a" />Apple
<input name="fruit[]" type="checkbox" value="o" />Orange

and PHP code to handle the checkbox values.

1
2
3
4
5
6
7
8
9
 $fruit = $_POST['fruit'];
 if(!empty($fruit))
 {
   foreach($fruit as $value)
   {
     $string = $value.','.$string;
   }
   $value = rtrim($value, ',');
 }