views:

42

answers:

1

Hello,

I am trying to display different divs depending on a selection from a drop down menu.

 <html>
<head>
<title>DDlist Div Display</title>
<script type="text/javascript">
function ShowDivArea(info) {
  var sel = document.getElementById('divArea').getElementsByTagName('div');  
  for (var i=0; i<sel.length; i++) { sel[i].style.display = 'none'; }
  if (info == '0') { return; }
  document.getElementById('divArea'+info).style.display = 'block';
}

</script>

<style type="text/css">
.divArea { display:none; height:100px; width:500px; border:1px solid red; }
</style>

</head>

    <body>

<select id="DDDivList" onchange="ShowDivArea(this.selectedIndex)">
  <option value="0" selected> -- Select A Design Service --</option>
  <option value="1"> QR Bookmark </option>
  <option value="2"> Twitter </option>
  <option value="3"> Ning or Tumblr </option>
  <option value="4"> Flyers </option>
  <option value="5"> Business Card or Brochure</option>
  <option value="6"> Album or Mixtape cover</option>
  <option value="7"> Other</option>
</select>

<div id="divArea">
 <div id="divArea1" class="divArea">

 <form action='code.php' method='GET'>
    <input type='text' name='myname'><br>
    <input type='submit' value='Click here'>
</form>

<?php


$name = $_GET['myname'];
if ($name)
echo "Hello, $name.";


?>


</div>
 <div id="divArea2" class="divArea">
</div>
</body>
</html>

You get the point from here on. More divs for each drop down option.

This is what I don't get: I want to add a different php script to each div. What should code.php be?

Thank you.

+1  A: 

This is what I don't get: I want to add a different php script to each div. What should code.php be?

You could include it, or simple insert it inline like you are currently doing.

Also, code.php can be anything you want. You'll probably want it to handle $_GET['myname'].

If you actually want code.php to be included there, try this

include 'code.php';

On a security note, echoing $name like that could leave you open to an XSS vulnerability, unless you escaping the $_GET super global of course (which is probably too much of a blanket solution).

alex
thank you. I tried including it ... but it still displays the The requested URL /code.php was not found on this server. I ll keep working on this.
ciprian