![]() |
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.
|
sstill,
CopperB is probably having problems because the instructions aren't terribly clear. Thank you for explaining "why" it works and all, but you're not clear for the folks who don't "already know" on how to implement it. For instance... you said... Quote:
Well... what does that mean....exactly? what is a javascript page? or somewhere on the page mean? Please post crystal clear instructions that illustrate what people are supposed to do. Quote:
Ok...now what? Replace it? add it above? add it below? amend to it? What are the people who don't know this stuff supposed to do when they get to line 188? Thanks for the mod...it's a great one. But to avoid many many replies and confusion and people tarsnishing your work with questions....you gotta be super duper clear when instructing people who to implement them. step by step. don't let people think on their own. *smile* - Shannon |
Here we go...
First of all I would like to say Thanks for this is a great little mod and Yes I agree it would have been much easier from the start to just say replace your giftcert.tpl with the code below. The code above was incomplete missing the javascript tags which most newbies would never even know and would be pulling their hair out not knowing why its not working, in addition I fixed a few out of place things to give it a cleaner look. Code below tested and works in 4.0.13
replace the entire contents of giftcert.tpl found in directory: /skin1/modules/Gift_Certificates/giftcert.tpl with the code below, tested and works in 4.0.13: Quote:
There is one annoying little glitch I did find which is also in the original giftcert.tpl template and that is in the To: email field there is a space that you have to delete out to enter your email, for the life of me I could'nt figure out how to get rid of the space, anyone? |
IndieDepot,
Thanks for the comments, your right, I could go into more detail, but then I have to assume a certain level of knowledge. If there is a questions such as you asked Quote:
That is what these forums are for, asking questions, getting directions. My mod is written for people who understand on a basic level the workings of Javascript, if you don't understand Javascript I would not attempt this mod. Unfortunatly because all carts differ in some ways I can't just flop out mod that is universal (or I would be charging for it.) Mostly the mods I post are things that I have done and posted in the hopes that someone can adapt it and apply it to their cart. No guarentees though, if you don't understand what something is ask or Google on it, if the directions are unclear ask. Simple as that. I hope I don't need to dumb things way down or put up disclaimers all over the place to keep people from shooting themselves in the foot. WARNING!! WARNING!! WARING!! This mod could distroy your cart, cost you millions of dollars in down time, bring about global warming, use all your mouse fluid, break the tip of our pencil, lower your chances at winning the lottery, etc. :wink: |
sstillwell,
I didn't mean to ruffle your feathers dude. All I did was make an observation on how you communicated as opposed to 95% of the other great mods posted on this wonderful website, and then I simply commented on it explaining why you had troubles with people right off the bat...and how you could avoid them in the future. Had I not said anything, then snorocket probably would have never came with his fix, and your great mod will have gone unused by many, MANY people when it didn't have to. I was always told "Don't Assume Anyting"...especially the level of compentence of others....espcially on a website where beginners come to learn. This is not a geeked-out hackers site...i don't think. *smile* Either way, I didn't mean to bend you outta shape about it. snorocket, Thanks for making a 'Universal' and 'Free' fix to the great mod posted by sstillwell. - Shannon |
IndieDepot,
No offense taken, I was just having a little fun at your expense. Seriously though, my mod was written in response to someone liking what I had done in a few places on my site. It is more of a concept that can be used in several different places than a specific mod. "Don't assume anything" is a nice cliche but you have to assume a level of knewledge. For example if I say 'ok edit the home.tpl file'. Do I not assume that they know how to edit a text file? Actually on these forums we have a wide range of knowledge from people who have no idea how to edit HTML to those that are coding PHP. So yes, there are geeks among us. In closing, I do appreciate all comments good/bad, they help me improve and that is what I am interested in. |
So, where the register.tpl code and java should be add?
|
Hide/Flip Shipping Fields?
Has anyone been able to succesfully hide/flip the shipping fields in register.tpl?
yea yea yea I know sstillwell posted the code to do this and it works perfectly but the formatting is the most horrendous thing I've ever come across. I've poked around the code for hours in an effort to fix the formatting with no progress, let us know if you have managed to hide/flip the shipping fields while retaining the same formatting as the orginal code, Thank You. |
Re: Hide/Flip Shipping Fields?
Quote:
Try This: Code:
{if $config.General.use_https_login eq "Y"} I would just like to figure out how to keep the Yes checked after the customer is registered with a different shipping address. So far it just defaults to No, confuses the customer if he wants to ship something to the billing address at a later time |
Quote:
Just a thought, but you could have smarty do a test on the value of the address fields. If it's the same then leave it as "no" if it is different then make it "yes". Code:
Shipping same as billing? Yes<input type="radio" name="shipping" {if $userinfo.s_address eq $userinfo.b_address} You'll also need to add that to the css that hides that block of markup. Code:
{if $userinfo.s_address eq $userinfo.b_address} I have not implemented this so it's just a guess. |
i keep getting an error in the javascript console in firefox that says "flipdiv is not defined" and nothing happens when i click yes or no
|
Re: Use Javascript and CSS to hid / flip visibilty of elements
This used to work really great in Explorer, Firefox and Opera.
Unfortunately it doesn't in Internet Explorer 7.0, I just noticed. Displaying the hidden content by clicking the radiobutton works fine, but clicking the hide radiobutton doesn't hide the content anymore... Anybody knows how to get this also working for Explorer 7.0? Many thanks in advance! |
Re: Use Javascript and CSS to hid / flip visibilty of elements
Just wanted to note, in 4.0.x and later of X-Cart a function to flipDiv's is already implemented.
Take a peek at skin1/common.js and you'll find: function visibleBox(id,skipOpenClose) Example in X-Cart that uses it is the search.php page "Advanced Search" opens the entire search form. Just setup your links for the open/close toggle with an id="closeX" and id="openX" the actual area that is hidden and appears would be id="boxX" X for all id's being an incremental number starting at 1 to whatever. Kudos! |
Re: Use Javascript and CSS to hid / flip visibilty of elements
Quote:
Yes, you are right. I just noticed this a few weeks ago and had to change the code to make it work. Right now, it's just a band aid and I'm not really sure why IE7 doesn't like the original. My opinion, IE7... still sucks. |
Re: Use Javascript and CSS to hid / flip visibilty of elements
Quote:
And that is why he is an Xcart Guru. Thanks B00MER. |
Re: Use Javascript and CSS to hid / flip visibilty of elements
wow that is a full waste of code right there.. Basically
onMouseover and onMouseCLick on the <a> and then call the appropriate css on off commands for the divs. simple.. no php no nothing.. just simple three lines of java, and css |
All times are GMT -8. The time now is 02:59 PM. |
Powered by vBulletin Version 3.5.4
Copyright ©2000 - 2025, Jelsoft Enterprises Ltd.