63 034
Assignments Done
99,1%
Successfully Done
In July 2018

Answer to Question #3710 in C# for Olufemi daniel

Question #3710
How can I validate text boxes using username and password
Expert's answer
<html>
<head>
& lt;script>

& function checkForm()
& {
& //-----------------------------------------------------------------------
& // text box
& var username = document.forms[0].txtUsername.value;
& if (username.length < 2 || username.length == 0 || username.length > 15)
& {
& alert("Username must be at least 2 chars and not more 15");
& return false;
& }
& //-----------------------------------------------------------------------
& // text box as password field
& var pass = document.forms[0].txtPassword.value;
& if (pass.length == 0)
& {
& alert("Plese, enter your password");
& return false;
& }
& //-----------------------------------------------------------------------
& // radio buttons
& var gender = document.forms[0].rGender;
& var genderChecked = false;
& for (var i = 0; i < gender.length; ++i)
& {
& if (gender[i].checked)
& {
& genderChecked = true;
& break;
& }
& }
& if (!genderChecked)
& {
& alert("Please, select your gender");
& return false;
& }
& //------------------------------------------------------------------------
& var browsers = document.forms[0].chbBrowsers;
& var browsersSelected = false;
& for (var i = 0; i < browsers.length; ++i)
& {
& if (browsers[i].checked)
& {
& browsersSelected = true;
& break;
& }
& }
& if (!browsersSelected)
& {
& alert("Please, select at least one browser");
& return false;
& }
& //------------------------------------------------------------------------
& alert("Validation complete. All is good!");
& return true;
& }
&
& lt;/script>
</head>

<body>
& lt;form name="formname" action="#" method="get" onsubmit="var result = checkForm(); return result;">
& lt;table>
lt;tr>
lt;td>
& Username
& lt;/td>
& lt;td>
& lt;input type="text" name="txtUsername" />
& lt;/td>
lt;/tr>
lt;tr>
lt;td>
& Password
& lt;/td>
& lt;td>
& lt;input type="password" name="txtPassword" />
& lt;/td>
lt;/tr>
& lt;tr>
lt;td>
& Gender
& lt;/td>
& lt;td>
& lt;input type="radio" name="rGender" value="male" /> Male
& lt;input type="radio" name="rGender" value="female" /> Female
& lt;/td>
lt;/tr>
& lt;tr>
lt;td>
& Browsers
& lt;/td>
& lt;td>
& lt;input type="checkbox" name="chbBrowsers" value="IE" />IE<br/>
& lt;input type="checkbox" name="chbBrowsers" value="Opera" />Opera<br/>
& lt;input type="checkbox" name="chbBrowsers" value="Google Chrome" />Google Chrome<br/>
& lt;input type="checkbox" name="chbBrowsers" value="Mozilla Firefox" />Mozilla Firefox
& lt;/td>
lt;/tr>
lt;tr>
lt;td colspan="2">
& lt;input type="submit" value="Submit" name="btnSubmit" />
& lt;/td>
lt;/tr>
lt;/table>
& lt;/form>
</body>
</html>

Need a fast expert's response?

Submit order

and get a quick answer at the best price

for any assignment or question with DETAILED EXPLANATIONS!

Comments

No comments. Be first!

Leave a comment

Ask Your question

Submit
Privacy policy Terms and Conditions