Thursday 8 October 2015

Radio Buttons- Show / Hide Form Fields

I was working for doctor's appointment system and required to show / hide some fields depending on the session of appointment. I have searched the internet but couldn't find the proper solution or a tutorial for it. And then I developed my own code just by using JavaScript. I am just copy-pasting my code over here.

Example Form Code:

<table>
<tr class="t-time-pers">
  <td class="t-time">
     <label for="time">Session</label>
     <div class="form-item">
     <input type="radio" id="morning1" name="session" value="Morning" checked>Morning <br/>
     <input type="radio" id="evening1" name="session" value="Evening">Evening
      </div>
    </td>
</tr>
<tr class="t-time-pers">
    <td class="t-time">
       <label for="time">Session</label>
          <div class="form-item" id="morning">
            <select name="time" id="morning" required>
               <option value="10.00 AM - 10.30 AM">10.00 AM - 10.30 AM</option>
               <option value="10.30 AM - 11.00 AM">10.30 AM - 11.00 AM</option>
       <option value="11.00 AM - 11.30 AM">11.00 AM - 11.30 AM</option>
               <option value="11.30 AM - 12.00 AM">11.30 AM - 12.00 PM</option>
      </select>
</div>
<div class="form-item" id="evening">
    <select name="time" id="evening" required>
        <option value="10.00 AM - 10.30 AM">04.00 PM - 04.30 PM</option>
         <option value="10.30 AM - 11.00 AM">04.30 PM - 05.00 PM</option>
 <option value="11.00 AM - 11.30 AM">05.00 PM - 05.30 PM</option>
           <option value="11.30 AM - 12.00 AM">05.30 PM - 06.00 PM</option>
</select>
      </td>
 </tr>
</table>


AND Put this JAVASCRIPT IN FOOTER just before closing </body> tag


<script>
/*Developed by Bhushan Bagde */
/*Radio Buttons enable and disable*/
$(document).ready(function(){
 $("#morning").show();
   $("#evening").hide();
$("#morning1").on("change", function(){
   $("#morning").show();
   $("#evening").hide();
});

$("#evening1").on("change", function(){
   $("#morning").hide();
   $("#evening").show(); 
});
})
</script>

That's it. You are not required to change css and other things to make it work. I hope you will like my code. If you have any doubts you can comment it here.

Thank You

Wednesday 19 August 2015

WooCommerce - Add Indian Rupee Symbol

Indian Government has launched its new currency symbol for Indian Rupee.

In WooCommerce we are not able to view our symbol and also many developers are not able to add it on their website.

If you are using WooCommerce for WordPress and want to add Indian Rupee Symbol in your website just follow the following steps.

STEP 1 : Open function.php file of your theme.

STEP 2: Add the following code in your function.php file and save it

<? 

/*** WooCommerce  Add Indian Currency by Bhushan Bagde ***/

add_filter( 'woocommerce_currencies', 'add_custom_currency' );

function add_custom_currency( $currencies ) {
$currencies["INR"] = 'Indian Rupee';
return $currencies;
}

add_filter('woocommerce_currency_symbol', 'add_custom_currency_symbol', 10, 2);

function add_custom_currency_symbol( $currency_symbol, $currency ) {
switch( $currency ) {
case 'INR': $currency_symbol = '&#8377'; break;
}
return $currency_symbol;
}


?>

Now, goto WooCommerce > Settings > Select Indian Currency.

That's it.

Thank You

Friday 7 August 2015

Remove .html or .php extension with .htaccess

.htaccess is a file which will help you to do
  1. Redirect the user to different page.
  2. Password protect a specific directory
  3. Block users by IP
  4. Preventing hot linking of your images
  5. Rewrite URIs
  6. Specify your own Error Documents

Removing Extensions

To remove the .php extension from a PHP file
for example the domain url is example.com/home.php and you want to change intoexample.com/home  so here you have to add the following code inside the .htaccess file:
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
 RewriteRule ^([^\.]+)$ $1.php [NC,L]
 </IfModule>


To remove the .html extension from a html file
If you want to remove the .html extension from a html file for example example.com/home.htmlto example.com/home you have to add the following code inside the .htaccess file:
<IfModule mod_rewrite.c>
 RewriteEngine On
 RewriteCond %{REQUEST_FILENAME} !-f
RewriteRule ^([^\.]+)$ $1.html [NC,L]
</IfModule>
That’s it! You can now link pages inside the HTML document without needing to add the extension of the page. For example:
<a href="http://www.example.com/services">services</a>