Skip to content

Instantly share code, notes, and snippets.

@EkremGungormez
Created March 9, 2012 14:54
Show Gist options
  • Save EkremGungormez/2006849 to your computer and use it in GitHub Desktop.
Save EkremGungormez/2006849 to your computer and use it in GitHub Desktop.
Simple Javascript Application
<head>
<script src="../../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
<script src="../../Scripts/jquery-ui-1.8.11.js" type="text/javascript"></script>
<link href="../../Content/themes/base/jquery.ui.all.css" rel="stylesheet" type="text/css" />
</head>
<body>
<h2>
Member Informations</h2>
@using (Html.BeginForm())
{
<div>
<table>
<tr>
<td>
Name
</td>
<td>@Html.TextBox("Name")
</td>
</tr>
<tr>
<td>
Birthday
</td>
<td>@Html.TextBox("DatePicker")
</td>
</tr>
<tr>
<td>
Email
</td>
<td>@Html.TextBox("Email")
</td>
</tr>
<tr>
<td>
Proficiency
</td>
<td>@Html.TextBox("Proficiency")
</td>
</tr>
<tr>
<td>
Gender
</td>
<td>@Html.RadioButton("Gender", "Male", false)Male @Html.RadioButton("Gender", "Female", false)Female
</td>
</tr>
<tr>
<td>
</td>
<td>
<input type="button" name="Submit" value="Add" onclick="AddElement()" />
</td>
</tr>
</table>
</div>
<ul id="myList">
</ul>
}
</body>
</html>
<script type="text/javascript">
$("#DatePicker").datepicker();
function AddElement() {
var date1 = new Date();
var today = new Date();
var date1 = $("#DatePicker").datepicker("getDate");
var age = today.getFullYear() - date1.getFullYear();
var gender;
switch ($("input[type='radio']:checked").val()) {
case "Male":
gender = "He";
break;
case "Female":
gender = "She";
break;
default:
break;
}
try {
if (age < 18)
1 = true; // to get error if user's younger than 18...
}
catch (e) {
alert($("#Name").val() + ", you must be at least 18 to login, sorry...");
return;
}
personObj = { firstname: $("#Name").val(), birthday: $("#DatePicker").datepicker("getDate"), email: $("#Email").val(), proficiency: $("#Proficiency").val(), gender: $("input[type='radio']:checked").val() }
var new_element = $("<li />").appendTo($("#myList"));
new_element.html(personObj.firstname + " is " + age + " years old. " + gender + " is " + personObj.proficiency);
}
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment