Note that there are some explanatory texts on larger screens.

plurals
  1. POshow div based on textbox value
    primarykey
    data
    text
    <p>I have a input field that gets it value from a db lets say the value is M,K,H,J,V or G depending on the value it needs to open the div with aaa,bbb,ccc,ddd,eee or fff as text.</p> <p>The code that is displayed on the page is as followed i left out the retrieval part from the db that part is working (the input box shows M,K,H,J,V or G depending on the id.)</p> <pre><code>echo "&lt;input type='text' name='periode' id='periode' data-related-item='" .$row['periode']. "' value='" .$row['periode']. "'&gt;"; echo "&lt;div class='hidden'&gt;&lt;div id='M'&gt;aaa&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='hidden'&gt;&lt;div id='K'&gt;bbb&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='hidden'&gt;&lt;div id='H'&gt;ccc&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='hidden'&gt;&lt;div id='J'&gt;ddd&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='hidden'&gt;&lt;div id='V'&gt;eee&lt;/div&gt;&lt;/div&gt;"; echo "&lt;div class='hidden'&gt;&lt;div id='G'&gt;fff&lt;/div&gt;&lt;/div&gt;"; </code></pre> <p>When i check the source code in developer mode it shows that the data-related-item part is correctly retrieved from the db:</p> <pre><code>&lt;input type="text" name="periode" id="periode" data-related-item="M" value="M"&gt; </code></pre> <p>I want to use the following JS but i need to change it to work with textboxes.</p> <pre><code>&lt;script type="text/javascript"&gt; function evaluate1(){ var item = $(this); var relatedItem = $("#" + item.attr("data-related-item")).parent(); if(item.is(":checked")){ relatedItem.fadeIn(); }else{ relatedItem.fadeOut(); } } $('input[type="checkbox"]').click(evaluate1).each(evaluate1); &lt;/script&gt; </code></pre> <p>The simplest approach is offcourse changing:</p> <pre><code>$('input[type="checkbox"]').click(evaluate1).each(evaluate1); </code></pre> <p>into</p> <pre><code>$('input[type="textbox"]').click(evaluate1).each(evaluate1); </code></pre> <p>But what do i need to do with:</p> <pre><code>if(item.is(":checked")){ </code></pre> <p>Thanks for any help in advance.</p> <p>I tried the following but it aint working.</p> <pre><code>if(item.is("M||K||H||J||V||G")){ </code></pre> <p><strong>SOLUTION BY ROBERT ROZAS</strong></p> <p>The solution is in jsfiddle </p> <p><a href="http://jsfiddle.net/dXTtz/7/" rel="nofollow">http://jsfiddle.net/dXTtz/7/</a></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.
    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