0

I am a newby so appologise for asking a basic question.

I have a php page - a 'create new project' page

There are some simple data such as name, deadline etc...

but depending on the type of the project I have 4 different ends (different pages?) in this FORM and I can't find the solution for it.

Here is my code:

<h1>New Project</h1>
<form name="newpr">
New project name:<input type="text" placeholder="new project name..."><br />
New project end date:<input type="text" placeholder="date..."><br />
New project type:
<select name="menu" onChange="location=document.newpr.menu.options[document.newpr.menu.selectedIndex].value;" >
<?php 
$listdata = mysql_query("SELECT * FROM lists WHERE tag='prtype' ORDER BY listing ASC");
while($listresult = mysql_fetch_array($listdata))
{
if ($listresult["listing"]!="...") $link=$listresult["value"].".php";
else $link="";

echo "<option value='".$link."'>".$listresult["listing"]."</option> ";
}
?>
</select>
</form>

As you see the select list comes from Mysql and I would like a div under a form to be able to open page1.php or page2.php etc as user selects...

Thanks in advance

Andras

it might be ajax question...

TryHarder
  • 750
  • 1
  • 9
  • 22
  • It looks like you're trying to forward a user depending on which select box to try, but in doing so you would not be forwarding the other options they input - Is this the issue you are having? – ChrisK Aug 23 '11 at 06:50
  • I would like add different questions to the form. My thought was to create these questions in different php files and open those but on the same pages... an this is where I am stuck. This code redirect to a different page which is wrong but this is how far I got. – TryHarder Aug 23 '11 at 06:55

2 Answers2

1

I'd solve this the following way

<!-- using jQuery -->

<h1>New Project</h1>

<form method="" action="post">
    New project name:<input type="text" placeholder="new project name..."><br/>
    New project end date:<input type="text" placeholder="date..."><br/>
    New project type:
    <select name="menu">
        <?php 
        $listdata = mysql_query("SELECT * FROM lists WHERE tag='prtype' ORDER BY listing ASC");
        while($listresult = mysql_fetch_array($listdata))
        {
            $link = '';
            if($listresult['listing'] != '...') {
                $links = $listresult['value'] . ".php";
                echo "<option value='$link'>${listresult['listing']}</option>";
            }
        }
        ?>
    </select>

    <div id="page">
        <!-- container for loaded page -->
    </div>

    <script type="text/javascript">
        $("select[name=menu]").change(function() {
            var url = $("option:selected", this).val();
            // Load a page to the container
            $("#page").load(url);
        });
    </script>
</form>

Using jQuery I added on change handler on select box and if it's changed it loads via ajax a page to the div container.

And let me give you and advice - try to avoid mixing code and html. It leads to difficulties in further development and maintenance.

Boris S
  • 301
  • 3
  • 10
  • Hi Boris, thanks very much indeed it is brilliant, it seems to work however the $link some reason didn't appear in the option. – TryHarder Aug 23 '11 at 07:31
  • Thanks again Boris! It is great and I have found the mistake instead of $links it is only $link - however your solution is brilliant. Thanks again!!!! – TryHarder Aug 23 '11 at 07:46
  • Honestly, I was more concentrated at html+js. And php, I'm forgeting it little by little. – Boris S Aug 29 '11 at 09:14
0

You want to make a HTTP request to your php page
Checkout
http://mootools.net/docs/core/Request/Request.HTML
http://mootools.net/docs/more/Request/Request.JSONP

Listen for the callback on your request then inject the returned data as an element into the DOM.
Mootools is my weapon of choice but Jquery etc. all have this same functionality.
call php page under Javascript function This question is very similar to yours.

Community
  • 1
  • 1
Tegra Detra
  • 24,551
  • 17
  • 53
  • 78
  • thanks for your help unfortunately I could not find a demo to be able to examine codes... without that it is a bit raw for me... could you give an example please? – TryHarder Aug 23 '11 at 07:16