Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>I made a few tweaks to get this to work:</p> <p>I updated the HTML to make the <code>td</code>s droppable. This seems to work a little bit better. I also changed the <code>colspan</code> attribute of the <code>td</code>s appropriately.</p> <p><strong>Updated HTML:</strong></p> <pre><code>&lt;div id="result_space"&gt; &lt;div id="player_list" class="player_list"&gt; &lt;p&gt;This is the player space &lt;/p&gt; &lt;div id="pos_1" class="player"&gt; &lt;p&gt;Player 1&lt;/p&gt; &lt;/div&gt; &lt;div id="pos_2" class="player"&gt; &lt;p&gt;Player 2 &lt;/p&gt; &lt;/div&gt; &lt;/div&gt; &lt;div id="pitch"&gt; &lt;form id="resultform" name="resultform" action="results_submit.php" method="post"&gt; &lt;table background="../_images/5_results/pitch_v2.jpg" width="560" border="1px"&gt; &lt;tbody&gt; &lt;tr height="30"&gt; &lt;td colspan="2" align="center" style="color: #FFFF00; font-size: 24px;" class=""&gt;stowupland falcons fc&lt;/td&gt; &lt;/tr&gt; &lt;tr height="80" valign="bottom"&gt; &lt;td colspan="2" align="center" class="position"&gt; &lt;div class="" id="goalie"&gt; &lt;input type="hidden" name="goalie" id="goalie" value="Player 1" /&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr height="110" align="center" valign="middle"&gt; &lt;td class="position"&gt; &lt;div id="defence1"&gt; &lt;input class="" type="hidden" name="r_def_1" id="r_def_1" value="player 2" /&gt; &lt;/div&gt; &lt;/td&gt; &lt;td class="position"&gt; &lt;div class="" id="defence2"&gt; &lt;input type="hidden" name="r_def_2" id="r_def_2" value="player 3" /&gt; &lt;/div&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/tbody&gt; &lt;/table&gt; &lt;input name="submit" type="submit" id="submit" value="Submit" /&gt; &lt;/form&gt; &lt;/div&gt; &lt;/div&gt; </code></pre> <p><strong>JavaScript:</strong></p> <pre><code>$(function() { $(".player").draggable({ revert: "invalid" }); $(".position").droppable({ activeClass: "ui-state-hover", hoverClass: "ui-state-active", accept: ".player", drop: function(event, ui) { var playerid = ui.draggable.attr("id"); $("input", this).val(playerid); } }); });​ </code></pre> <p>The key is this line:</p> <pre><code>$("input", this).val(playerid); </code></pre> <p>which finds the <code>input</code> inside of the droppable <code>td</code>.</p> <p><strong>CSS (with draggable its useful to limit the <code>width</code> of draggable items)</strong>:</p> <p>​<code>.player { width: 75px; }​</code></p> <p><strong>Example:</strong> <a href="http://jsfiddle.net/z8pWN/" rel="nofollow">http://jsfiddle.net/z8pWN/</a></p>
    singulars
    1. This table or related slice is empty.
    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. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      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