show/hide div +form

JavaScript and client side scripting.

Moderator: General Moderators

Post Reply
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

show/hide div +form

Post by bob_the _builder »

Hi,

I am using the following peice of code to show/hide a div tag:

<a href="#" id="pform-show" class="showLink" onclick="showHide(\'pform\');return false;">Contact us about this product</a>

Once clicked it shows the form, if the form is submited but has errors the page reloads, but the div is closed. Is there away to make it open the div tag after the form is submited so the missed fields can be corrected and/or the success message be displayed?

Thanks
User avatar
RobertGonzalez
Site Administrator
Posts: 14293
Joined: Tue Sep 09, 2003 6:04 pm
Location: Fremont, CA, USA

Re: show/hide div +form

Post by RobertGonzalez »

Moved to Client Side.

Can you show your JS code that does the showing and hiding?
bob_the _builder
Forum Contributor
Posts: 131
Joined: Sat Aug 28, 2004 12:25 am

Re: show/hide div +form

Post by bob_the _builder »

Hi,

Javascript is:

Code: Select all

function showHide(shID) {
    if (document.getElementById(shID)) {
        if (document.getElementById(shID+'-show').style.display != 'none') {
            document.getElementById(shID+'-show').style.display = 'none';
            document.getElementById(shID).style.display = 'block';
        }
        else {
            document.getElementById(shID+'-show').style.display = 'inline';
            document.getElementById(shID).style.display = 'none';
        }
    }
}
Thanks
User avatar
JAB Creations
DevNet Resident
Posts: 2341
Joined: Thu Jan 13, 2005 6:44 pm
Location: Sarasota Florida
Contact:

Re: show/hide div +form

Post by JAB Creations »

Change Class Function

Code: Select all

// Class Changefunction change(id, newClass){identity=document.getElementById(id);identity.className=newClass;} 
Using Change Class Function

Code: Select all

change('my_id', 'my_new_class');
Set Style By Id Function

Code: Select all

function setstylebyid(i, p, v) {var n = document.getElementById(i);if (n != null) {n.style[p] = v;}}
Using Set Style By Id Function

Code: Select all

setstylebyid('my_id_1', 'display', 'none');setstylebyid('my_id_2', 'color', '#123cdf');setstylebyid('my_id_3', 'border-left', '#123 solid 1px');
Post Reply