Note that there are some explanatory texts on larger screens.

plurals
  1. POPHP/HTML/Javascript: How to add value to a div element?
    primarykey
    data
    text
    <p><strong>My Problem was:</strong> Add a value to a div element in a dropdown list.</p> <p>Ok Guys, I've resolved my problem with the help of @David.</p> <p>I've always wanted to know how to design the <code>&lt;select&gt;</code> <code>&lt;option&gt;</code> tags, but now I think I found a solution to get away from them and use whatever element I want. Ok here is my code:</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Untitled Document&lt;/title&gt; &lt;script&gt; function getValue(value){ var valueHolder = document.getElementById('valueHolder'); valueHolder.value = value; } function toggle(id){ var element = document.getElementById(id); if(element.style.display == "none"){ element.style.display = "block"; } else { element.style.display = "none"; } } &lt;/script&gt; &lt;/head&gt; &lt;body&gt; &lt;form action="test2.php" method="post"&gt; &lt;input type="hidden" id="valueHolder" value="" name="valueHolder"&gt;&lt;/input&gt; &lt;div onclick="toggle('dropdown');"&gt;Show Dropdown&lt;/div&gt; &lt;div class="dropdown" id="dropdown" style="display:none;"&gt; &lt;div class="option" onclick="getValue('red')"&gt;Red&lt;/div&gt; &lt;div class="option" onclick="getValue('green')"&gt;Green&lt;/div&gt; &lt;/div&gt; &lt;input type="submit" name="submit" /&gt; &lt;?php if(isset($_POST['submit'])){ echo $_POST['valueHolder']; } ?&gt; &lt;/form&gt; &lt;/body&gt; &lt;/html&gt; </code></pre> <p>It's a bit ugly but check it out, works! Don't forget to run on a server.</p> <p>Best Regards, Adam</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload