So I searched forever to find something useful, there were tons of people asking this and getting answers but mainly for PHP, MVC apsx and so on which didn't help me at all so now I'm asking here! While I see how learning MVC probably could be beneficial but I'm doing somewhat of a small project for personal use only so I didn't bother as I didn't understand much!
Anyhow I want to send radiobutton values to the database and I'm kind of lost.
I have a form post in the html which sends my other textbox inputs and stuff but I want the radios as well.
{@
var getData = Database.Open("MyDatabase");
var Kg = Request.Form["Kg"];
var Sett = Request.Form["Sett"];
var Rep = Request.Form["Rep"];
var Date = Request.Form["Date"];
if (IsPost && Validation.IsValid()) {
if (ModelState.IsValid) {
var insertData = "INSERT INTO Test (kg, sett, rep, date) " +
"VALUES (@0, @1, @2, @3)";
getData.Execute(insertData, Kg, Sett, Rep, Date);
Response.Redirect("~/default");
}
}
}
So this above is how I send the textbox stuff to the database
<form method="post" action="">
<fieldset>
<label>Choice 1</label>
<input type="radio" name="Exercise" value="1" checked="checked" />
<label>Choice 2</label>
<input type="radio" name="Exercise" value="2" />
<input placeholder="Weight" name="Kg" type="text" size="50" value="@Kg" />
</fieldset>
</form>
and this above is in the html body, this isnt all of it as I have 6 radios and 4 textboxes but I didnt feel pasting all of them as it probably would be a mess to read.
but would I do the same way for the radios as the textboxes by adding a for example
var choice1 = Request.Form["Exercise"];
and put
@choice1
in the input value? And can all the radio inputs have the same name=""?, they do now as they had to because of a javascript that makes only one being selected at any time. The values sent to the db is fine to me if they are just either 1 or 2!