2

Once I have several submit buttons that send post data:

<form name="Master" form action="Master.php" method="post">
<table width="800" border="0">
  <tr>
    <td><input name="Master" type="submit" value="Test1"/></td>
    <td><input name="Master" type="submit" value="Test2"/></td>
  </tr>
</table>
</form>

Now I change my mind, and want to use drop down menus:

<ul class="menu" id="menu">
    <li ><a href="" class="menulink">Home</a>
    <li ><a href="" class="menulink">Main1</a>
        <ul>
            <li><a href="" class="sub">Test1</a>
            <li><a href="" class="sub">Test2</a>
        </ul>
</li>
</ul>

CSS code (menu, menulink, sub, etc) properly displays this menus.

But I dont want to chage substantially the php file that handles the original post values.

So my question is:

Can I send use "method post" inside this dropdown menu? How?

Thanxs.

8
  • you can send data to server as GET request via an anchor tag, but POST is not possible :( Commented Mar 1, 2014 at 17:14
  • 1
    Why is there a form attribute in the first HTML example? Commented Mar 1, 2014 at 17:14
  • 3
    You can do the exact same thing are you had previously. Just style your buttons so they look like a normal link. Commented Mar 1, 2014 at 17:14
  • @rvighne Please read the question. OP is using buttons to submit POST data to the server. Commented Mar 1, 2014 at 17:15
  • 1
    @rvighne Sorry, I misunderstood what you said. I agree with you. Commented Mar 1, 2014 at 17:18

2 Answers 2

1

As Justin already commented, just add a form to your dropdown menu's and submit it just like you did in code 1.

<form name="Master" action="Master.php" method="post">
<ul class="menu" id="menu">
        <ul>
            <li><input name="test" type="submit" class="sub" value="test1"/>
        </ul>
</li>
</ul>
</form>
Sign up to request clarification or add additional context in comments.

Comments

0

To best preserve the look and feel of the links, you will need to use JavaScript. With your second example, remove the href attributes and include this script (untested):

var form = document.createElement('form');
form.action = "Master.php";
form.method = "post";

window.onload = function() {
    var menu = document.getElementById('menu');
    menu.onclick = function(e) {
        var link = e.target || e.srcElement;
        if (link.tagName !== "A") return;

        var input = document.createElement('input');
        input.name = "Master";
        input.value = link.textContent || link.innerText;
        form.appendChild(input);
        form.submit();
    };
};

Alternatively, you could wrap your second example in a <form> and change the anchors to inputs, like this:

<form name="Master" action="Master.php" method="post">
    <ul class="menu" id="menu">
        <li ><input name="Master" type="submit" value="Home" />
        <li ><input name="Master" type="submit" value="Main1" />
            <ul>
                <li><input name="Master" type="submit" value="Test1" />
                <li><input name="Master" type="submit" value="Test2" />
            </ul>
        </li>
    </ul>
</form>

Then, in your CSS, make the inputs look like links. For example, remove all borders, padding, margin, background colors, and text colors; and set font to inherit. Then apply any extra styling.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.