Reputation: 259
I have a razor @Html.RadioButtonFor, which takes its value from @Html.TextBoxFor value:
@Html.RadioButtonFor(m => m.Sms, document.getElementById('@(Model.Phone)').value, new { Id = Model.Sms })
The problem is that
document.getElementById('@(Model.Phone)').value
is a JavaScript code, incorect in this context, but I have no idea how to rewrite the same code so it is correct.
Upvotes: 0
Views: 1961
Reputation: 7692
Paul, I had to make it the other way: from the textbox onChange
, set the radio value.
Check this out:
@model string
<!DOCTYPE html>
<html>
<head>
<title>ViewA</title>
<script type="text/javascript">
function changeRadioValue(newValue) {
var radio = document.getElementById('idRadio');
if (radio != null) {
radio.value = newValue;
}
else {
//do nothing?
}
}
</script>
</head>
<body>
<div>
@Html.TextBox("theTextBox", Model, new { id = Model, onChange = "changeRadioValue(this.value)" })
@Html.RadioButton("radio", "Default radio value", new { id = "idRadio", onClick="alert(this.value)" })
</div>
</body>
</html>
The radio onClick
is only for debugging.
Hope this helps
Regards
Upvotes: 2