Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Have Programming Question? Ask it here!
 
 
 


Jeevan kumar
javascript
1 Answer(s)      3 years and 9 months ago
Posted in : JSP-Interview Questions


<HTML> <HEAD> <TITLE>validate

<Script language = JavaScript>

function validate(theForm) {

var why="";

why += checkDropdown(theForm.choose.selectedIndex);

why += checkRadio(theForm.radios);

if (why != "") { alert(why); return false; } return true; }

function checkDropdown(choice) { var error = ""; if (choice == 0) { error = "You didn't choose an option from the drop-down list.\n"; } return error; }

function checkRadio(checkvalue) { var error = "";

for (i=0, n=theForm.radios.length; i

if (!(checkvalue)) { error = "Please check a radio button.\n"; } return error; } <BODY>

Male Female


Advertisement
View Answers

November 17, 2010 at 11:39 AM


Hi Friend,

We have modified your code:

<Script language = JavaScript>
function validate() {
var checkD= checkDropdown(document.f1.choose.selectedIndex);
var checkR = checkRadio(document.f1.radios.value);
if (checkD != "") {
alert(checkD);
return false;
}
if (checkR != "") {
alert(checkR);
return false;
}

return true;
}

function checkDropdown(choice) {
var error = "";
if (choice == 0) {
error = "You didn't choose an option from the drop-down list.\n";
}
return error;
}

function checkRadio(checkvalue) {
var error = "";

for (i=0, n=document.f1.radios.length; i<n; i++) {
if (document.f1.radios[i].checked) {
var checkvalue = document.f1.radios[i].value;
break;
}
}

if (!(checkvalue)) {
error = "Please check a radio button.\n";
}
return error;
}
</SCRIPT>
</HEAD>

<form name="f1" onsubmit ="return validate();">
<SELECT NAME = choose >
<OPTION VALUE = "select">select</OPTION>
<OPTION VALUE = "NE" >North East</OPTION>
<OPTION VALUE = "NW">North West</OPTION>
<OPTION VALUE = "SE">South East</OPTION>
<OPTION VALUE = "SW">South West</OPTION>
<OPTION VALUE = "Midlands">Midlands</OPTION>
</SELECT>

<input type="radio" name="radios" value="male">Male <input type="radio" name="radios" value="Female">Female<br /><br />
<input name="Submit" value="Send" type="submit" >

</form>

Thanks



Related Tutorials/Questions & Answers:
JavaScript
JavaScript  clone JavaScript
javascript
javascript  javascript code to dynamically add table on button click.../javascript/javascriptexamples/javascript-add-row-dynamically.shtml http://www.roseindia.net/javascript/javascript-add-row-to-table.shtml http://www.roseindia.net
Advertisements
JavaScript
should use JavaScript? Thanks   Hi, JavaScript is scripting language that runs on browser. You have to embed JavaScript in HTML page. Please see JavaScript tutorial. Thanks
JavaScript
JavaScript  how to get full path of a file type in javascript
javascript
javascript  Hi deepak, how to write form validation on javascript
javascript
javascript  i have just learned javascript... can you tell me what kind of applications can be made by javascript?? thank you
javascript
javascript  how to set the request or session attribute in javascript head part of jsp page
JAVASCRIPT
JAVASCRIPT  I have one textbox and I want to validate that it must start with number(1-0). can anyone tell me a javascript for that ? thanks in advance
Javascript
Javascript   Javascript to check Numeric entry in checkbox.....   Hi Please find the following code for numeric entry validation in javascript function validateBox(){ var data=document.myForm.someText.value
javascript
javascript  passing javascript values to jsp   Hi Friend, Try the following code: form.jsp: <html> <script> function getMsg...;/script> <input type="button" onclick="getMsg();" value="Get Javascript value
Javascript
this format xxx-xxx-xxxx, i want the code in javascript. as a function.   Javascript Phone Number Validation <html> <script> function..." method="post" onsubmit="javascript:return validate();"> Phone Number:<
Javascript
Javascript  Dear Sir, Thank You a lot for your continuos support.Again i am in need of your help. What is the javascript code to disable a link,once... javascript or css Please help me.Urgent Regards Debasis   Hello Friend
Javascript
Javascript  <html> <head> <script type="text/javascript"> function validateForm() { var sname=document.getElementById('spocname'); var scontact=document.getElementById('spoccontact'); if(sname.value.length
javascript
javascript  Hi deepak, sample example on javascript form validation   <html> <script> function checkName(text) { if(isNaN(text)){ return 1; } else{ alert("Please enter a valid name. The only charachters
JavaScript types
JavaScript types  What are JavaScript types
javascript doubt
javascript doubt  How to retrieving the values from Database by using javascript
JavaScript and ECMAScript
JavaScript and ECMAScript  What?s relationship between JavaScript and ECMAScript
javascript validation
javascript validation  validation of comparing dropdownlist and textbox in javascript
JavaScript - JavaScript Tutorial
JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified into sections with examples. This tutorial
JavaScript - JavaScript Tutorial
JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified into sections with examples. This tutorial
Prototypes for JavaScript
Prototypes for JavaScript  What's Prototypes for JavaScript
Prototypes for JavaScript
Prototypes for JavaScript  What's Prototypes for JavaScript
javascript and database
javascript and database  i want to connect javascript pages with msaccess (as a database)how can i do so
javascript query
javascript query  how to get javascript variable value into java variable?? i have one value in javascript variable(var name = value ) i want this name variable value in java variable (string name1
validations in javascript
validations in javascript  How do you check validations in javascript
javascript conversion
javascript conversion  how to convert war file into dll file
javascript validation
javascript validation  How to do javascript validations to check whether the entered primary key is present in the database or not .Iam using jsp language
javascript validation
javascript validation  How to do javascript validations to check whether the entered primary key is present in the database or not .Iam using jsp language
JavaScript - JavaScript Tutorial
JavaScript - JavaScript Tutorial JavaScript Tutorials is one of the best Quick reference to the JavaScript. In this JavaScript reference you will find most of the things about java script. JavaScript tutorial is classified
Acrobat Javascript
Acrobat Javascript  i want to know about complete tutorial of Acrobat javascript in brief
javascript - XML
javascript  HI, Greetings.... I want to call javascript file i.e. ".js" from xml file. If it is possible tell me how to do that. and i want to know how to call javascript function from xml... Please help me in this regard
JavaScript basic
JavaScript basic  What does "1"+2+4 evaluate to?   Since "1" is a string, everything is a string, so the result is a string of "124
JavaScript basic
JavaScript basic  How about 2+5+"8"?   Since 2 and 5 are integers, this is number arithmetic, since 8 is a string, it?s concatenation, so 78 is the result
Javascript and flex
Javascript and flex  Hi..... How do you call javascript from Flex... the ExternalInterface API to access JavaScript from Flex. In flex application, you may have called function defined in action script. Sometimes you may need to call a javascript
JavaScript basic
JavaScript basic  What is === operator ?   The ==== operator is strict equality operator, it returns true only when the two operands are having the same value without any type conversion
Embedded JavaScript
Embedded JavaScript       Embedded JavaScript (EJS) is an open source JavaScript template library. Read full Description
javascript validation
javascript validation  i have 4 buttons in my project like save,find,modify,clear and exit. Here my problem is i have to validate in javascript like if i click on save button an alert message should be displayed "DO YOU WANT
Javascript loops
Javascript loops  Write a JavaScript code, - for guessing any number between 1 to 20. run the loop till you not get correct number. Use prompt...: <SCRIPT LANGUAGE="JavaScript"> var guess; var rno=Math.round(Math.random
javascript - Ajax
click on particular image of slide show in javascript. i used href tag but it does not work so i m posting my javascript code here below. note: in the head
Javascript array
Javascript array  Write a javascript code to,(numerically) Enter the array size from the user Input the array elements from the user display the array elements reverses it and display   Hello Friend, Try this: <
Javascript & jsp
Javascript & jsp  Dear Sir, Thanks a ton for all your answers throughout.I asked this question long ago.This time i nedd it very urgent.I think it might be a short solution.How can i get the navigation link whilr traversing
Advertisements
 

 

 

DMCA.com