views:

53

answers:

4
+1  Q: 

Javascript Menu

I am working on a page, which has a link which reads "update". When users click this link, I would like a form to use a slide effect and appear underneath the link. When the form is submitted, it updates the db, and the menu vansihes.

I know this can be done with javascript, but I am not sure how to implement it.

Much thanks

+1  A: 

First off, use jquery, it will be simpler and compliant cross browser.

Appearing with a slide effect can be done with Jquery UI.

$("div").click(function () {
      $(this).show("slide", { direction: "down" }, 1000);
});

Updating the db assynchronously can be done using the post method:

$.post("/action.php", { },
      function(data){
    }, "text");

... but you can also simply post the form synchronously and refresh the page.

marcgg
seems almost perfect, but can you explain it a bit furthur? is "div" the div id? Also, how to I get a form to appear with this effect
Steven1350
div is how you identify the element you want to appear. read up a bit on jquery selectors to get this. You've got stuff here: http://docs.jquery.com/Selectors and all over google. If you want to show a form like this, wrap the form in a div with an id and call the function on this div. Of course at the begining the form needs to be hidden (style='display:none')
marcgg
You don't need jQuery UI... jQuery is enough - plus a call to animate()
J-P
You can do without just using the show('slow') function, but it's always nice to know jquery UI
marcgg
A: 

You can do this using JQuery or AJAX toolkit on ASP.NET. WHIch language do you want it in? It cannot be done in pure javascript only

waqasahmed
Ajax is a part of javascript, stop talking rubbish.
scragar
A: 

May I also add that you will need to ensure the page works without javascript as well, many users, myself included surf with javascript disabled. And I personally would abandon your site if key functionality was sacrificed so you can make the page look prettier.

scragar
A: 

You should consider a javascript library such as jQuery to help you achieve this. Basically what you need is to create a DIV at disired position and hide it when the document finishes loading then add events for the menu click

With jQuery:

$(document).ready(function() {

        $('#myDivId').hide(); //Hiding the div

        $('#updadeLinkId').click(function() {
             $('#myDivId').slideToggle('slow'); //This is the slide effect
        });

    });

The jQuery library can be downloadeds at http://www.jquery.com/

Raphael
I'm not a big fan of $('#myDivId').hide(); on document ready because it might display the div and then hide it... which is not really pretty for the end user
marcgg
That has never happened to me. Good to know
Raphael