Register  |  Login




Advertisement

Start Your Own Q&A Site

Create your own Q&A site easily, allowing you to quickly grow a new community around any subject matter or generate new organic traffic for your existing website.

Question

Status: Open Points: 125 Time: 00:04 - May 29, 2007  

mdjinna

How can i validate checkboxlist in javascript?

validate the checkboxlist in the java script

Categories

Answer Discussion
Tutorials

 

nidhi

Date:: Jan 29, 2009

Time:: 09:16

What do you mean by checkboxlist ? Unless that is something new, I am not sure of what that is. You either have one or more checkboxes, any of which can be selected or if you want just one choice then its a radio button choice

nidhi

Date:: Jan 29, 2009

Time:: 09:32

Simple radio button validation. Form which asks you to select a fruit. Note, the form submit specifies to call a javascript function. In that I iterate thru the radio buttons, make sure the buttons have the same name

In checkFruitEntered code, I set a variable to be -1. If a fruit is selected then I set it to that index. see the final if in that method.


<html>
<head><title>radio btn validation</title></head>

<script language="JavaScript">
function checkFruitEntered() {

 var fruitSelected = -1;

 for (i = 0; i < quomonTest.rbtn.length; i++) {
  if (quomonTest.rbtn[i].checked) {
   fruitSelected = i;
  }
 }


 if (fruitSelected == -1) {
  alert("You didnt select a fruit!");
  return false;
 } else {
  alert("You selected " + quomonTest.rbtn[fruitSelected].value);
  return true;
 }
}
</script>

<body>

<form name="quomonTest" onSubmit="return checkFruitEntered()">
Select A Fruit :
<input type="radio" name="rbtn" value="apple">I like Apples
<input type="radio" name="rbtn" value="pear">I need some Pears
<input type="radio" name="rbtn" value="bananas">I love Bananas
<br>
<input type="submit">
</form>

</body>
</html>

nidhi

Date:: Jan 29, 2009

Time:: 09:34

forgot to add, to get to the form variable in javascript, do the following

<formname>.<field name>

in this case, formname is quomonTest (code=<form name="quomonTest") and field is called rbtn (code=name="rbtn")

admin

Date:: Mar 24, 2009

Time:: 09:45

The question looks to be abandoned by the user who asked it. If no action is taken within 2 days, a Quomon Moderator will consider closing the question and distributing the points.

The Quomon Team

Answer this Question

New User

Email:

Upon submission of this form, you will automatically be registered as a Quomon user and we will send your login information to this address

Registered User

Username:

Password:

Forgot Your Password?

Tutorials cannot be submitted until the Answer Discussion is complete.

Submit answers in the Answer Discussion area

Ask a Question

Have a new question? Ask!

You have 100 characters to use



Top Experts

View More

Rank

Expert

Points

1.

nidhi

10279

2.

oracleofDelphi

6493

3.

rcastagna

5596

4.

LAGM

4848

5.

PeterNZ

3487

6.

gonzalo

2840

7.

Mason

2770

8.

jgivoni

2303

9.

xarcus

1820

10.

Anpanman

917

Become an Expert

Register today to share your knowledge with the community and be recognized and rewarded for your contributions.


Register Here




"Psst, Quomon is a great site. Pass it on."     Tell a Friend  |   Link To Us  |   Save to Delicious  |   Digg! Digg it



Language Options

English:

www.quomon.com

Español:

www.quomon.es