0

I'm using this code to change the include path with javascript:

$('#actionLink').attr('href', $('#actionLink').attr('href')  + '?page=welcome');


 switch($_GET['page'])) {
     case 'welcome':
         include 'section/welcome.html';
         break;
     case 'nda':
         include 'section/nda.html';
         break;
 }

But how do this using a submitbutton?

1
  • What is #actionLink, and how do you get the page containing the PHP includes ? Commented Jun 24, 2013 at 11:49

4 Answers 4

1

To show the page URL names on the buttons:

<form method="get" action="<this page's address>">
    <input type="submit" name="page" value="page1" />
    <input type="submit" name="page" value="page2" />
</form>

Or, to show other text there:

<form method="get" action="<this page's address>">
    <input type="submit" name="page" value="Page 1 button text" onclick="this.value='page1'" />
    <input type="submit" name="page" value="Page 2 button text" onclick="this.value='page2'" />
</form>

Or lastly, with a hidden field & jQuery:

<form method="get" action="<this page's address>">
    <input type="submit" value="Page 1 button text" onclick="$('#hidden').val('page1')" />
    <input type="submit" value="Page 2 button text" onclick="$('#hidden').val('page2')" />
    <input type="hidden" name="page" id="hidden" />
</form>
Sign up to request clarification or add additional context in comments.

Comments

0
$('button').onclick(function() {
$(location).attr('href', 'www.example.com'); //redirect to www.example.com
});

Comments

0

Simply do it in HTML.

 <form method="GET" action="?page=whatever">
     <input type="submit" value="Click Me!" />
 </form>

Comments

0

You can try this:

<form method="POST" action="yourpage.php">
     ....
     <input type="hidden" name="page" id="page" value="welcome">
     <input type="submit" value="submit" />
 </form>

// $_REQUEST works for both $_GET and $_POST
switch($_REQUEST['page'])) {
     case 'welcome':
         include 'section/welcome.html';
         break;
     case 'nda':
         include 'section/nda.html';
         break;
 }

I hope this can be of some help.

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.