![]() |
Use Javascript and CSS to hid / flip visibilty of elements
I use this trick on a few different places on my site. It came about after using some less computer savvy people here at work to try to use the site. Mostly to hide parts of a form that a user doesn't need to see unless some criteria is met. Helps so they don't get confused as we know most users don't read.
Examples. Gift Certificate page http://www.aerostich.com/giftcert.php The registration / checkout pages (shipping address is hidden) https://www.aerostich.com/register.php All we are doing is making a block of html code visible or hiding it. I'll go through the process for the gift certificate page. Step 1 This javascript function should be either in your javascript page or in the head or somewhere on the page. Code:
// Function to flip visibility of certain div objects Step 2 skin1/modules/Gift_Certificates/giftcert.tpl Starting at about line 188 Code:
<TR><TD colspan="3"></TD></TR> In the above code you will notice a few things that are essential to making it work. 1. The table tag containing the differnt deliver fields are as follows: The email table tag Code:
<table id="sendbyemail" {if $giftcert.send_via eq "P"}style="display: none;"{/if}> Code:
<table id="sendbypostal" {if $giftcert.send_via ne "P"}style="display: none;"{/if}> Send Via Email radio button Code:
<INPUT type="radio" name="send_via" value="E" {if $giftcert.send_via ne "P"}checked{/if} onClick="flipdiv('sendbyemail','show'); flipdiv('sendbypostal','hide');" /> Code:
<INPUT type="radio" name="send_via" value="P" {if $giftcert.send_via eq "P"}checked{/if} onClick="flipdiv('sendbyemail','hide'); flipdiv('sendbypostal','show');" /> That's it, you can use it to hid several things on a page and make them appear. Have fun! |
nicely done
|
This is great. I really appreciate this mod. Looks good and very user friendly.
Will you be posting the code for the registration / checkout pages (shipping address is hidden)? Unfortunately when I comes to java I am a complete novice. Thanks |
Quote:
CopperB, I've modded my skin1/customer/main/register.tpl a bit. Here is what I have. Code:
<tr> That's it, along with the essential javascript flipdiv function you can do that to most any block type HTML tags. I would give more advice, but like I said, I have changed the layout of my register forms which changes the HTML from the default install. Also, just an FYI, it's JavaScript. It's completely different from Java, why it was named JavaScript is beyond me, but it is not Java at all. I think when it first came out it was called Livescript by Netscape but someone changed it to JavaScript to jump on the then Java Band Wagon. |
Once again great mod. I have the register working just fine but am having some trouble with the Gift Certificate page.
If the customer chooses send via Email the form cannot be sent because the code is looking for the required fields of the postal address. Any ideas? I haven't changed the code you posted for the giftcert template at all. Thanks |
Quote:
If customers are selecting "Send via Email" and they are getting prompted to fill in the postal info, then you have some problems with the code you altered. We are not changing the logic, just the display of those fields. Post your code and maybe we can give you a hand. |
Sorry I should have been more clear. They are not getting prompted for Postal info. I tested it out and found that even though Email was selected it wouldn't send without the Postal info included.
Here is my giftcert code. Code:
{* $Id: giftcert.tpl,v 1.37.2.3 2004/09/15 12:01:51 max Exp $ *} Here is a link to the page: http://www.copperboppers.com/xcart/giftcert.php Thanks for the help. |
Is it possible to have the "No" selected if the shipping address is already filled in once the customer is registered?
|
Bump...
Any idea why when Email is selected it won't send without the Postal info included. I have posted my Giftcert code above. Thanks |
Sorry, CopperB, I took a brief look at your code and didn't see anything glaringly wrong. Maybe start over and implement very small changes until you see what is breaking it.
|
All times are GMT -8. The time now is 10:16 AM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.