简体   繁体   中英

Display php in divs using javascript

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.

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, echo ing $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).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM