Jump to content

Drop down with php


cip6791

Recommended Posts

Hello,

 

I'm trying to use a dropdown to display different divs.

 

<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.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:200px; 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">

 

 

<h1>QR Bookmarks</h1>

<form action='qrgen.php' method='POST'>

<input type='text' name='bmarksite'> URL<br>

<input type='text' name='sitedesc'> Description<br>

<input type='submit' value='Convert'><br>

 

<?php

 

include("QrCodes.php")

?>

 

<?php

 

$bmarksite = $_POST['bmarksite'];

$sitedesc = $_POST['sitedesc'];

 

if ($sitedesc&&$bmarksite)

{

$qrcode = new QrCodes;

$qrcode -> IsImage =1;

echo $qrcode -> GetBookmark("$bmarksite","$sitedesc");

echo "</br>";

echo $bmarksite;

echo "</br>";

print $sitedesc;

 

}

 

else

{

echo "Please fill in all the required fields.";

}

?>

 

 

</div>

<div id="divArea2" class="divArea">Twitter</div>

<div id="divArea3" class="divArea">Ning or Tumblr</div>

<div id="divArea4" class="divArea">Flyers</div>

<div id="divArea5" class="divArea">Business Card or Brochure</div>

<div id="divArea6" class="divArea">Album or Mixtape Cover</div>

<div id="divArea7" class="divArea">Other</div>

</div>

 

</body>

</html>

 

The problem is with this line: <form action='qrgen.php' method='POST'>. I am using a wordpress page template. What should I change the qrgen.php to? Or how do I get it to work?

 

Thank you for your help.

Link to comment
Share on other sites

I'm working on a similar problem.

 

I found this http://bytes.com/topic/javascript/answers/88791-show-hide-text-form-field-based-drop-down-selection Look at the reply that Mrk put. His is done with tables but you can easily put your divs in the tables. In order to do what your trying to do you need javascript

 

Like i said though i'm doing the exact same thing right now so if you go with this and get stuck let me know i've almost got it working how i need it too.

Link to comment
Share on other sites

Ya i got it working. Heres a working code for 7 divs.

<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<meta http-equiv="Content-type" content="text/html; charset=utf-8" />
<title>Show/Hide</title>
<script type="text/javascript">
// <![CDATA[
function display(obj,id1,id2,id3,id4,id5,id6,id7) {
txt = obj.options[obj.selectedIndex].value;
document.getElementById(id1).style.display = 'none';
document.getElementById(id2).style.display = 'none';
document.getElementById(id3).style.display = 'none';
document.getElementById(id4).style.display = 'none';
document.getElementById(id5).style.display = 'none';
document.getElementById(id6).style.display = 'none';
document.getElementById(id7).style.display = 'none';

if ( txt.match(id1) ) {
document.getElementById(id1).style.display = 'block';
}
if ( txt.match(id2) ) {
document.getElementById(id2).style.display = 'block';
}
if ( txt.match(id3) ) {
document.getElementById(id3).style.display = 'block';
}
if ( txt.match(id4) ) {
document.getElementById(id4).style.display = 'block';
}
if ( txt.match(id5) ) {
document.getElementById(id5).style.display = 'block';
}
if ( txt.match(id6) ) {
document.getElementById(id6).style.display = 'block';
}
if ( txt.match(id7) ) {
document.getElementById(id7).style.display = 'block';
}
}
// ]]>
</script>
</head>
<body>
<table width="500" cellspacing="0" cellpadding="0">
<thead>
<tr>
<td width="303" class="title">Select a Design Service</td>
<td width="195" class="field">
<select name="type" onChange="display(this,'1','2','3','4','5','6','7');">
  <option value="s" selected>Please Select...</option>
  <option value="1">QR Bookmaek</option>
  <option value="2">Twitter</option>
  <option value="3">Ning or Tumblr</option>
  <option value="4">Flyers</option>
  <option value="5">Business Cards or Brochure</option>
  <option value="6">Album or Mixtape Cover</option>
  <option value="7">Other</option>
</select>
</td>
</tr>
</thead>
<tfoot>
</tfoot>

<tbody id="1" style="display: none;">
  <tr><td><br>

<div>1</div>

</td></tr>    
</tbody>

<tbody id="2" style="display: none;">
  <tr><td><br>

<div>2</div>

</td></tr>    
</tbody>

<tbody id="3" style="display: none;">
  <tr><td><br>

<div>3</div>

</td></tr>    
</tbody>
<tbody id="4" style="display: none;">
  <tr><td><br>

<div>4</div>

</td></tr>    
</tbody>
<tbody id="5" style="display: none;">
  <tr><td><br>

<div>5</div>

</td></tr>    
</tbody>
<tbody id="6" style="display: none;">
  <tr><td><br>

<div>6</div>

</td></tr>    
</tbody>
<tbody id="7" style="display: none;">
  <tr><td><br>

<div>7</div>

</td></tr>    
</tbody>
<tbody>
</tbody>
</table>
</body>
</html>

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.