Note that there are some explanatory texts on larger screens.

plurals
  1. POHow to create a text box after selecting an option from drop-down list?
    text
    copied!<p>I'm trying to create a drop-down list with four options such that if I select the 4th option, I want a text box created so that I can get the value typed in that box using "$_GET"</p> <p>Something like this;</p> <pre><code>&lt;select name="value"&gt; &lt;option value="value1"&gt;Option 1&lt;/option&gt; &lt;option value="value2"&gt;Option 2&lt;/option&gt; &lt;option value="value3"&gt;Option 3&lt;/option&gt; &lt;!-- And a 4th one --&gt; &lt;/select&gt; </code></pre> <p>And if the 4th one is selected, a box should appear like this;</p> <pre><code>&lt;input type="text" name="firstname"&gt; </code></pre> <hr> <p>Edit; </p> <p>My current code;</p> <pre><code>&lt;script&gt; jQuery(function($){ //calling the code inside braces when document loads and passing jQuery object as '$' parameter; $("select[name='sortby']").change(function(){ //binding an event that fires every time select value changes var select = $(this); //caching select, which value was changed if(select.val() === "byDefindex"){ //checking if we selected the right option $("&lt;input&gt;").attr({type: "text", name: "defindex"}).appendTo(select.parent()); //creating new input element object, setting its value to "value4" and appending to select parent element or wherever you want it } }); }); &lt;/script&gt; &lt;form action="&lt;?php $_PHP_SELF ?&gt;" method="GET"&gt; Select: &lt;br /&gt; &lt;select name="sortby"&gt; &lt;option value="playHours"&gt;Play Hours&lt;/option&gt; &lt;option value="lastLogin"&gt;Last Login&lt;/option&gt; &lt;option value="byDefindex"&gt;By Defindex&lt;/option&gt; &lt;/select&gt; &lt;br /&gt; &lt;input type="submit" /&gt; &lt;/form&gt; </code></pre>
 

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