JavaScriptを使用してテキストボックスを無効にし、チェックされているラジオボタンに基づいて価格を計算しています。
私が抱えている問題は、ラジオボタンのグループ名を使用して正しいテキストボックスを見つけ、その値を計算に使用することです。リピーターが私のitemtemplateからコードを作成するとき、名前を作成するために提供された引数を使用しません。
アイテムタグの私の名前は次のとおりです。name='<%#DataBinder.Eval(Container.DataItem、 "idtag_domain")%>'作成される名前は、name = "Repeater1 $ ctl02$textbox"と指定した名前タグです。 。ラジオボタンの場合、その名前はRepeater1 $ ctl01 $ sverigemotrasismになります。これは、sverigemotrasismだけで はありません。名前の作成を停止する方法はありますか...またはそれを回避するにはどうすればよいですか?
これは私のitemtemplateです
<ItemTemplate>
<asp:RadioButton id="RadioButton1" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>' value="50" Text="Fri tillgång" onclick="calculatePrice();disableTB(this.name);" />
<br />
<asp:RadioButton id="RadioButton2" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>'
Text="En artikel om dagen(30/mån)" value="25" onclick="calculatePrice();disableTB(this.name);" />
<br />
<asp:RadioButton id="RadioButton3" runat="server" GroupName='<%# DataBinder.Eval(Container.DataItem, "idtag_domain")%>' value="0"
Text="Skriv antalet artiklar" onclick="enableTB(this.name, this.checked)" />
<br />
<asp:TextBox ID="textbox" runat="server" name='<%# DataBinder.Eval(Container.DataItem, "idtag_domain") %>' Enabled="false" Width="106px"
onkeyup="calculatePrice()" style="background-color:#eeeeee" ></asp:TextBox>
</ItemTemplate>
私のJavaScriptはこれを行います!クリックされたテキストボックスを確認します。
function enableTB(tbname, checked)
{
var textboxen = tbname;
document.getElementById(textboxen).disabled = !checked;
document.getElementById(textboxen).style.background = '#C4F8CC';
}
function disableTB(tbname)
{
var textboxen = tbname + 1;
document.getElementById(textboxen).disabled = true;
document.getElementById(textboxen).style.background = '#eeeeee';
}
残念ながら、これはリピーターがすべてを作成した後の私のソースコードのようになります...リピーターデータ!
<table>
<input id="Repeater1_RadioButton1_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="50" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton1_0">Fri tillgång</label>
<br />
<input id="Repeater1_RadioButton2_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="25" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton2_0">En artikel om dagen(30/mån)</label>
<br />
<input id="Repeater1_RadioButton3_0" type="radio" name="Repeater1$ctl01$sverigemotrasism" value="0" onclick="enableTB(this.name, this.checked);" /><label for="Repeater1_RadioButton3_0">Skriv antalet artiklar</label>
<br />
<input name="Repeater1$ctl01$textbox" type="text" id="Repeater1_textbox_0" disabled="disabled" class="aspNetDisabled" onkeyup="calculatePrice()" name="sverigemotrasism" style="width:106px;background-color:#eeeeee" />
<tr>
<td>
</td>
</tr>
<input id="Repeater1_RadioButton1_1" type="radio" name="Repeater1$ctl02$handlaihop" value="50" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton1_1">Fri tillgång</label>
<br />
<input id="Repeater1_RadioButton2_1" type="radio" name="Repeater1$ctl02$handlaihop" value="25" onclick="calculatePrice();disableTB(this.name);" /><label for="Repeater1_RadioButton2_1">En artikel om dagen(30/mån)</label>
<br />
<input id="Repeater1_RadioButton3_1" type="radio" name="Repeater1$ctl02$handlaihop" value="0" onclick="enableTB(this.name, this.checked);" /><label for="Repeater1_RadioButton3_1">Skriv antalet artiklar</label>
<br />
<input name="Repeater1$ctl02$textbox" type="text" id="Repeater1_textbox_1" disabled="disabled" class="aspNetDisabled" onkeyup="calculatePrice()" name="handlaihop" style="width:106px;background-color:#eeeeee" />