Jump to content

onlick show a form


arbitter

Recommended Posts

Hello,

 

I'm new to javascript and can't figure out how to do this. What I want is that there when you click on 'login', underneath it a form appears with 2 fields and a submit button.

 

Now, I can manage the form, but I don't know how to do the javascript part... Can someone get me started please?

Link to comment
Share on other sites

Is there a shorter version of this. I made it so it toggles between "Edit Profile" and "Cancel"

 

<div id="showEditLink" style="block">
      <a href="#" onclick="document.getElementById('edit').style.display='block';document.getElementById('profile').style.display='none';document.getElementById('showProfileLink').style.display='block';document.getElementById('showEditLink').style.display='none';">Edit Profile</a>
</div>

<div id="showProfileLink" style="display:none">
  <a href="#" onclick="document.getElementById('edit').style.display='none';document.getElementById('showEditLink').style.display='block';document.getElementById('showProfileLink').style.display='none';document.getElementById('profile').style.display='block';">Cancel</a>
</div>

<div id="edit" style="display:none;">
 Name: <input value="Sean"/>	  
</div>

<div id="profile" style="display:block;">
Name: Sean
</div>

 

Link to comment
Share on other sites

Try something like this. The first is just javascript, the second uses the jquery library ( <3 ) to hit all the classes you want to show / hide and change the element's display accordingly.

 


<!--    // functionized! //   -->

<script type="text/javascript">

    function show(which){
    
        if(which=='profile'){
        
            document.getElementById('edit').style.display='none';
            document.getElementById('showEditLink').style.display='block';
            document.getElementById('showProfileLink').style.display='none';
            document.getElementById('profile').style.display='block';
        
        }else{
        
            document.getElementById('edit').style.display='block';
            document.getElementById('profile').style.display='none';
            document.getElementById('showProfileLink').style.display='block';
            document.getElementById('showEditLink').style.display='none';
        
        }//end if
    
    }//end function

</script>

<div id="showEditLink" style="block">
      <a href="#" onclick="show('edit');">Edit Profile</a>
</div>

<div id="showProfileLink" style="display:none">
  <a href="#" onclick="show('profile');">Cancel</a>
</div>

<div id="edit" style="display:none;">
 Name: <input value="Sean"/>	  
</div>

<div id="profile" style="display:block;">
Name: Sean
</div>

<!--       // jquery //           -->

<script type="text/javascript" src="http://jqueryjs.googlecode.com/files/jquery-1.3.2.min.js"></script>

<script type="text/javascript">
    
    function toggle(show,hide){
    
        $("."+show).each(function(){
        
            $(this).css("display","block");
        
        });
        
        $("."+hide).each(function(){
        
            $(this).css("display","none");
        
        });
    
    }//end function
    
</script>

<div class="second" style="block">
      <a href="#" onclick="show('first');">Edit Profile</a>
</div>

<div class="first" style="display:none">
  <a href="#" onclick="show('second');">Cancel</a>
</div>

<div class="first" style="display:none;">
 Name: <input value="Sean"/>	  
</div>

<div class="second" style="display:block;">
Name: Sean
</div>

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.