Login    Forum    Search    FAQ   Blog

Board index » Client-Side Development » Javascript




 Page 1 of 1 [ 4 posts ] 



Author Message
 Post subject: checkbox selection
 Post Posted: Mon Feb 23, 2009 1:07 pm 
Offline

Joined: Sat Feb 21, 2009 3:15 pm
Posts: 41
can any one tell me how to know which checkbox is selected and what value is selected in a dropdown list....in javascript code...can any one give sample code.. I had both check boxes and dropdown list in my webpage and i want to know which checkbox is selected and what value is selected from dropdown list..


Top 
 Post subject: Re: checkbox selection
 Post Posted: Mon Feb 23, 2009 1:18 pm 
Offline
Site Admin

Joined: Thu Jan 08, 2009 10:26 pm
Posts: 20
welcome to the forums

to get value of dropdown
document.myform.mylist.value

where myform is name of form and mylist is the name of dropdown,similarly to check the dropdown

if(document.myform.chkboxid.checked){

// if it is checked do some thing
}

_________________
Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row or

Go to http://www.55deals.com to save money on deals.


Top 
 Post subject: Re: checkbox selection
 Post Posted: Mon Feb 23, 2009 1:35 pm 
Offline

Joined: Sat Feb 21, 2009 3:15 pm
Posts: 41
i did get you clearly

<html>
<head>
<title>view .</title>
</head>
<body>
<form action=" " name="myform" method="post">
<p> some </p>
<select name="csome">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select><br />
<pre>
Size <INPUT TYPE=TEXT NAME=size
SIZE=20 VALUE=""><BR>
</pre>
<INPUT TYPE="checkbox" NAME="B[]" Value="B1" CHECKED>B1<BR>
<INPUT TYPE="checkbox" NAME="B[]" Value="B2">B2<BR>
<INPUT TYPE="checkbox" NAME="B[]" Value="B3">B3<BR>
<INPUT TYPE="checkbox" NAME="B[]" Value="B4">B4<BR>
<input type="submit" value="Submit">
</form>
</body>
</html>

this is the form but where to call the function to give selected checkbox and I want all checkboxex selected to be stored in an array...and where should i call get function for selecting dropdown menu...

can u tell me for this form...


Top 
 Post subject: Re: checkbox selection
 Post Posted: Mon Feb 23, 2009 1:48 pm 
Offline
Site Admin

Joined: Thu Jan 08, 2009 10:26 pm
Posts: 20
Code:
<html>
<head>
<title>view .</title>
<script type="text/javascript">
function fnclick(){
var w = document.myform.csome.selectedIndex;
var selected_text = document.myform.csome.options[w].text;

var A = new Array();
var str = "";
for(var i=0; i < document.myform.B.length; i++){
if(document.myform.B[i].checked){
    A[i] = document.myform.B[i].value;
    str = str + "," + document.myform.B[i].value;
  }
}
//alert("selected checkboxes : " + str);

}

</script>
</head>

<body>
<form action=" " name="myform" method="post">
<p> some </p>
<select name="csome">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
<option>6</option>
<option>7</option>
<option>8</option>
<option>9</option>
<option>10</option>
</select><br />

<pre>
Size <INPUT TYPE=TEXT NAME=size
SIZE=20 VALUE=""><BR>
</pre>

<INPUT TYPE="checkbox" NAME="B" Value="B1" CHECKED>B1<BR>
<INPUT TYPE="checkbox" NAME="B" Value="B2">B2<BR>
<INPUT TYPE="checkbox" NAME="B" Value="B3">B3<BR>
<INPUT TYPE="checkbox" NAME="B" Value="B4">B4<BR>

<input type="submit" value="Submit" onclick="fnclick()">
</form>
</body>

</html>


Please note that str is not required, i have kept it for your understanding. Array a has the values of checkboxes selected.

_________________
Want to Make $$$$ with your Computer? No Risk! Simply press shift-4 four times in a row or

Go to http://www.55deals.com to save money on deals.


Top 
Display posts from previous:  Sort by  
 
 Page 1 of 1 [ 4 posts ] 




Board index » Client-Side Development » Javascript


Who is online

Users browsing this forum: No registered users and 1 guest

 
 

 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
cron