Note that there are some explanatory texts on larger screens.

plurals
  1. POHighlighting on click textbox divs with css and javascript
    primarykey
    data
    text
    <p>I am using the following code to highlight the div of the text box that the user has clicked on. My problem is that i have mulitple divs and textboxes which need to highlight when clicked on but if you click on one textbox all the divs highlight. When they should highlight one at a time (when clicked).</p> <p>.aspx code</p> <pre><code> &lt;div class="divSurname" runat="server"&gt; &lt;div id ="divLastName" class="on"&gt; &lt;asp:TextBox class="resizedTextbox" ID="txtSurname" onfocus="ChangeStyle(this);" onblur="ToggleStyle(this);" runat="server"&gt;&lt;/asp:TextBox&gt; &lt;asp:CustomValidator ID="cvSurname" runat="server" ValidateEmptyText="true" ControlToValidate="txtSurname" ErrorMessage="Please enter your Surname name." Display="Dynamic" OnServerValidate="cvSurname_ServerValidate" /&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p>and similar code for Firstname postcode etc..</p> <p>javascript</p> <pre><code> &lt;script type="text/javascript"&gt; function ToggleStyle(ctrl) { (document.getElementById('divLastName')).className = "on"; (document.getElementById('divStartName')).className = "on"; (document.getElementById('divDateOfBirth')).className = "on"; (document.getElementById('divClientPostcode')).className = "on"; } function ChangeStyle(ctrl) { (document.getElementById('divLastName')).className = "off"; (document.getElementById('divStartName')).className = "off"; (document.getElementById('divDateOfBirth')).className = "off"; (document.getElementById('divClientPostcode')).className = "off"; } &lt;/script&gt; </code></pre> <p>Css</p> <pre><code> #divLastName.on { background-color: #fff5cc; } #divLastName.on:hover { background-color: #fcd619; } #divLastName.off { background-color: #fcd619; } #divStartName.on { background-color: #fff5cc; } #divStartName.on:hover { background-color: #fcd619; } #divStartName.off { background-color: #fcd619; } #divDateOfBirth.on { background-color: #fff5cc; } #divDateOfBirth.on:hover { background-color: #fcd619; } #divDateOfBirth.off { background-color: #fcd619; } #divClientPostcode.on { background-color: #fff5cc; } #divClientPostcode.on:hover { background-color: #fcd619; } #divClientPostcode.off { background-color: #fcd619; } </code></pre> <p>Thanks in advance for any help!</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.
    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