Note that there are some explanatory texts on larger screens.

plurals
  1. POjs/jQuery moving label values to defaults
    primarykey
    data
    text
    <p>I want to use jQuery/js to do the following:</p> <ol> <li>Get the values of the labels of form inputs</li> <li>Put those labels as values in the inputs themselves</li> <li>Hide the labels</li> </ol> <p>Pretty straightforward. Since I don't want to have to type out </p> <pre><code>$('firstname input').val('First Name'); $('lastname input').val('Last Name'); $('street input').val('Street'); $('city input').val('City'); </code></pre> <p>etc., how can I go about pulling the label from each element and pasting it into that element's input box?</p> <p>Here's a slightly abbreviated version of the HTML:</p> <pre><code>&lt;form action="/" method="post" id="user-register-form" accept-charset="UTF-8"&gt; &lt;div&gt; &lt;div id="customreg"&gt; &lt;div class="firstname"&gt; &lt;div class="form-item form-type-textfield form-item-first-name"&gt; &lt;label for="edit-first-name"&gt; First Name &lt;span class="form-required" title="This field is required."&gt;*&lt;/span&gt; &lt;/label&gt; &lt;input type="text" id="edit-first-name" name="first_name" value="" size="24" maxlength="128" class="form-text required" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;div class="lastname"&gt; &lt;div class="form-item form-type-textfield form-item-last-name"&gt; &lt;label for="edit-last-name"&gt; Last Name &lt;span class="form-required" title="This field is required."&gt;*&lt;/span&gt; &lt;/label&gt; &lt;input type="text" id="edit-last-name" name="last_name" value="" size="24" maxlength="128" class="form-text required" /&gt; &lt;/div&gt; &lt;/div&gt; &lt;/div&gt; &lt;input type="submit" id="edit-submit--3" name="op" value="Join!" class="form-submit" /&gt; &lt;input type="hidden" name="form_build_id" value="form-5DDdSC4UFk_YPJIfuJgMhC4215CYJneg9PBDdetJtDQ" /&gt; &lt;input type="hidden" name="form_id" value="custreg_user_register_form" /&gt; &lt;/div&gt; &lt;/form&gt; </code></pre>
    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