Saturday 25 May 2013

Jquery multiple checkbox check to enable button



Select single checkbox and a submit button that is initially disabled. When checking a box the button is enabled and when unchecking , the button is disabled again.
if two checkboxes checked then button is disabled, if one check box is checked then button is enabled. 

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Jquery multiple checkbox check to enable button</title>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.2/jquery.min.js"></script>
<script>
$(document).ready( function(){
$('.chkbox').click( function() {
    if ($('.chkbox:checked').length==1) {
$('#add1').removeAttr("disabled");
$('#add2').removeAttr("disabled");
}
else{
$('#add1').attr("disabled","true");
$('#add2').attr("disabled","true");
}
});
});
</script>
</head>
<body>
<h3>Select atleast one checkbox to enable button</h3>
<br />
<input type="checkbox" class="chkbox" /><br />
<input type="checkbox" class="chkbox"/><br />
<input type="checkbox" class="chkbox"/><br />
<input type="checkbox" class="chkbox"/><br />
<input type="checkbox" class="chkbox"/>
<br />
<input id='add1' type='button' value='Submit' disabled='disabled'>
<input id='add2' type='button' value='Submit' disabled='disabled'>
<h3>Try to select two checkboxs to enable button</h3>
</body>
</html>


Jquery multiple checkbox check to enable button

Select atleast one checkbox to enable button







Try to select two checkboxs to enable button

Allow Alphanumeric (Alphabets & Numbers) Characters in Textbox using JQuery

Here I will show how to use JQuery to allow only alphanumeric characters in textbox or make textbox to allow only alphabets & numbers using JQuery.

<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>jQuery Allow only alphanumeric characters in textbox</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.8.2.js"></script>
<script type="text/javascript">
$(function () {
$('#txtNumeric').keydown(function (e) {
if (e.shiftKey || e.ctrlKey || e.altKey) {
e.preventDefault();
else {
var key = e.keyCode;
if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90) || (key >= 48 && key <= 57) || (key >= 96 && key <= 105))) {
e.preventDefault();
}
}
});
});
</script>
</head>
<body>
<div>
<b>Enter Text:</b><input type="text" id="txtNumeric" />
</div>
</body>
</html>

jQuery Allow only alphanumeric characters in textbox
Enter Text:

Saturday 18 May 2013

Make link prompt visitor to download .PDF, .DOC, or other file


In some situations when you're creating a web page with links to an Adobe Acrobat .PDF, Microsoft Word. DOC, Microsoft Excel .XLS, or other external program file, you may want the Internet browser to prompt the user to download the file instead of opening it in the browser window or in the external program. There are a few different methods you can do this.
  1.  We recommend on the web page that the user right-click the link and choose the option to Save or Save as the file.
  2.  Save the file within a compressed format such as a .ZIP file.
  3. Create the below PHP file that can be used to open .PDF files and if modified, .DOC or other files.
3a. Start by creating a new file on your server or on your computer called download.php3b. Once this file has been created copy and paste the below code into the file.
<?php if (isset($_GET['file'])) {
$file = $_GET['file'];
if (file_exists($file) && is_readable($file) && preg_match('/\.pdf$/',$file)) {
header('Content-Type: application/pdf');
header("Content-Disposition: attachment; filename=\"$file\"");
readfile($file);
}
} else {
header("HTTP/1.0 404 Not Found");
echo "<h1>Error 404: File Not Found: <br /><em>$file</em></h1>";
}
?>
3c. Once the above has been done, save the file and if needed upload to the server hosting your web page.
3d. Finally, once uploaded, all future .PDF links that you want to be downloaded instead of opened in the browser will need to point to download.php?file=example.pdf, where example.pdf is the name of the PDF you wish for the user to download. Below is an example of what a full link could look like.
<a href="http://www.computerhope.com/download.php?file=example.pdf">Click here to download PDF</a>