[RESOLVED]trouble getting value of a table TD and copying the value to other columns.

Hi All,

i have a table with a contextmenu attached to it, when the user enters a value in either a textbox or a drop down box they have the option to right click and select "Copy Down" if they click this i want to use Jquery to select the value of the column they have
clicked and copy its content down, so say i have 50 rows within the table, and they choose a value on the first row within a column and select copy down, i would like the value they have entered replicated all throughout the existing rows, but every time i
click Copy Down it copies the row it was clicked on and inserts it again with a duplicate row number, which isnt what i want, im new to JQuery so please help me.

heres my JQuery and html table

$(function () {
$('#grdvHandSets>tbody>tr').contextMenu(
[
{ 'Copy Down': function (menuItem, menu)
{
$(this).clone(true, true).insertAfter(this)
}
}
], { theme: 'vista' })
})
<table cellspacing="0" id="grdvHandSets" style="border-collapse:collapse;">
<tr>
<th scope="col">R</th><th scope="col">MobileNumber</th><th scope="col">Type</th><th scope="col">PortingFrom</th><th scope="col">Username</th><th scope="col">Type of use</th><th scope="col">Tariff Name</th><th scope="col">Tariff Code</th><th scope="col">SOC Name</th><th scope="col">SOC Code</th><th scope="col">Contract Term</th><th scope="col">Handset Description</th><th scope="col">Phone Cover</th><th scope="col">PAC Code</th><th scope="col">Con Date</th><th scope="col">X</th>
</tr><tr>
<td>
<span id="lblRowNumber" class="gvItem">1</span>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtMobileNumber" type="text" maxlength="11" id="txtMobileNumber" class="phonenumber number" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl02$drpType" id="drpType">
<option value=""></option>
<option selected="selected" value="1">New</option>
<option value="2">Upg</option>
<option value="3">Port</option>
<option value="4">Migr</option>
<option value="5">SOC</option>

</select>
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl02$drpPortingFrom" onchange="javascript:setTimeout('__doPostBack('ctl00$MainContent$grdvHandSets$ctl02$drpPortingFrom','')', 0)" id="drpPortingFrom">
<option selected="selected" value=""></option>
<option value="Vodafone">Vodafone</option>
<option value="O2">O2</option>
<option value="Three">Three</option>
<option value="Orange">Orange</option>
<option value="TMobile">TMobile</option>
<option value="Virgin">Virgin</option>
<option value="BT">BT</option>
<option value="CW">CW</option>
<option value="Tesco">Tesco</option>

</select>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtUsername" type="text" maxlength="100" id="txtUsername" class="handsetDetails" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl02$drpUseType" id="drpUseType">
<option value=""></option>
<option selected="selected" value="1">Indivi</option>
<option value="2">Parent</option>
<option value="3">Sharer</option>

</select>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtTariffName" type="text" value="3gb mobile broadband" maxlength="100" id="txtTariffName" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtTariffCode" type="text" maxlength="50" id="txtTariffCode" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtSocName" type="text" maxlength="100" id="txtSocName" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtSocCode" type="text" maxlength="50" id="txtSocCode" class="handsetDetails" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl02$drpContractTerm" id="drpContractTerm">
<option value=""></option>
<option value="36">36m</option>
<option selected="selected" value="24">24m</option>
<option value="18">18m</option>
<option value="12">12m</option>

</select>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtHandsetDescription" type="text" value="microsim" maxlength="200" id="txtHandsetDescription" class="handsetDetails" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl02$drpPhoneCover" id="drpPhoneCover">
<option selected="selected" value=""></option>
<option value="SIL">SIL</option>
<option value="GLD">GLD</option>
<option value="PLT">PLT</option>
<option value="DIA">DIA</option>

</select>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtPACCode" type="text" maxlength="12" id="txtPACCode" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl02$txtConDate" type="text" autocomplete="off" maxlength="10" id="txtConDate" class="date" />
</td><td>
<a onclick="javascript:return confirm('Are you sure you want to delete this handset row 12780');" id="lnkDelete" href="javascript:WebForm_DoPostBackWithOptions(new WebForm_PostBackOptions(&quot;ctl00$MainContent$grdvHandSets$ctl02$lnkDelete&quot;, &quot;&quot;, true, &quot;&quot;, &quot;&quot;, false, true))">
X</a>
</td>
</tr>
<tr>
<td>
<span id="lblRowNumber" class="gvItem">2</span>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl03$txtMobileNumber" type="text" maxlength="11" id="txtMobileNumber" class="phonenumber number" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl03$drpType" id="drpType">
<option value=""></option>
<option selected="selected" value="1">New</option>
<option value="2">Upg</option>
<option value="3">Port</option>
<option value="4">Migr</option>
<option value="5">SOC</option>

</select>
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl03$drpPortingFrom" onchange="javascript:setTimeout('__doPostBack('ctl00$MainContent$grdvHandSets$ctl03$drpPortingFrom','')', 0)" id="drpPortingFrom">
<option selected="selected" value=""></option>
<option value="Vodafone">Vodafone</option>
<option value="O2">O2</option>
<option value="Three">Three</option>
<option value="Orange">Orange</option>
<option value="TMobile">TMobile</option>
<option value="Virgin">Virgin</option>
<option value="BT">BT</option>
<option value="CW">CW</option>
<option value="Tesco">Tesco</option>

</select>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl03$txtUsername" type="text" maxlength="100" id="txtUsername" class="handsetDetails" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl03$drpUseType" id="drpUseType">
<option value=""></option>
<option selected="selected" value="1">Indivi</option>
<option value="2">Parent</option>
<option value="3">Sharer</option>

</select>
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl03$txtTariffName" type="text" value="3gb mobile broadband" maxlength="100" id="txtTariffName" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl03$txtTariffCode" type="text" maxlength="50" id="txtTariffCode" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl03$txtSocName" type="text" maxlength="100" id="txtSocName" class="handsetDetails" />
</td><td>
<input name="ctl00$MainContent$grdvHandSets$ctl03$txtSocCode" type="text" maxlength="50" id="txtSocCode" class="handsetDetails" />
</td><td>
<select name="ctl00$MainContent$grdvHandSets$ctl03$drpContractTerm" id="drpContractTerm">
<option value=""></option>
<option value="36">36m</option>
<option selected="selected" value="24">24m</option>
<option value="18">18m</option>
<option value="12">12m</option>
</tr>
</table>

anyone?

That is a long code that may keep people aways from reading it.

I had a similiar artilce about dynamic form, hopfully that will give you an idea about your question

http://blog.platformular.com/2012/03/13/dynamic-form-in-asp-net-mvc-jquery/

Leave a Reply