Monthly Archives: June 2011

How to enable or disable the form elements using jquery

If you want to disable or enable the form elements according to id or name under certain conditions using jquery below sample may help you to some extent.
Enable or Disable the form elements according to name

 $('input[type=submit]').attr("disabled","disabled"); //Disable
                  $('input[type=submit]').removeAttr('disabled');             //enable
                  $('input[type=text]').attr("disabled","disabled");           //Disable textbox
                  $('input[type=text]').attr("disabled",false);


Getting Value of the select box and text box:

var selected_value =  $("select[name='name_of_selectbox'] option:selected").val();
var selected_value_of_textbox =  $("input[name='name_of_selectbox'] ").val();
var selected_value_of_textbox1 =  $("input#id_of_textbox ").val();

Similar links
Link1
Link 2
Link 3

jQuery onchange-onfocus select box

If you need to bind a function to be called when a user selects an option from a select box using jQuery, you’ve come to the right place.

There are several different ways to skin this cat, but basically here is what we are going to do:

1. Bind a change event listener to the select box itself
2. When the box is changed, call a function that detects and retrieves the selected value

Here’s the code:
Sample 1


<script type="text/javascript">
$(function(){
$('#selectboxid').change(function(){
	  
          var selected = $("#selectboxid option:selected");
	    if(selected.val() == 0 ){
	        alert('Select Module');	
	     }else{	
	        do something;
		}
	});
});
</script>

Sample 2

script type="javascript">
$(document).ready(function(){     //$(function(){
$("#selectBoxId").change(function(){
var selectedValue = $(this).find(":selected").val();
alert('The selected value is'+selectedValue);
});
});
<script>

Similar Links:
jQuery
Jquery tutorial Site
Select Box on Change
onchange select box

How to find the Current URL in PHP

For Introduction Click Me
How to find the current Domain in PHP?

If you need the current domain of the site/url .Here is the sample code

<?php
// Using HTTP_HOST

$domain_name = $_SERVER['HTTP_HOST'];
echo $domain_name;
?>

if the current url structure is:http://redirect4.xyz. Remember http://www. part is excluded. The output will be phpfresher.com
If you need to make the link please concatenate the http://www. part with the output

How to display a different image for each day of the week using php

Description

This PHP script will get the day of the week from the server date and then display an image (jpg or gif) to match.
The code

<?php

/**

 * Change the name of the image folder

 *

 * Images must be named Monday.gif, Tuesday.gif etc

 */
// Change to the location of the folder containing the images

$image_folder = "images/days";

// You do not need to edit below this line
$today = date('l');

if (file_exists($image_folder."/".$today.".gif")) {

  echo "<img src=\"$image_folder/".$today.".gif\">";

}

else {

  echo "No image was found for $today";

}

?> 

How to remove all characters except letters and numbers from a string

Description
If you want to strip a string of all symbols and characters other than alphanumeric letters and numbers then use this. It will take a string and erase / delete any non-alphanumeric characters, and then output a clean version without the unwanted characters.
The code

<?php

$string = "i love php fresher numbers 12345 and symbols !£$%^&";

$new_string = ereg_replace("[^A-Za-z0-9]", "", $string);

echo $new_string

?>