View Full Version : select all
night star
دوشنبه 11 آبان 1388, 11:03 صبح
سلام
چه طور میشه یکسری chkbox همه با هم انتخاب بشه یعنی با کلیک روی یک گزینه یا دکمه همه انتخاب بشن و دوباره با زدن یک submit همه این اطلاعات وارد بانک بشن به طوری که داخل رکوردهای جدا ذخیره بشن
هواشناس
دوشنبه 11 آبان 1388, 12:09 عصر
بنام خدا
كد جاواي زير رو مثلا بصورت فايل selectallcheckbox.js ذخيره و ضميمه صفحه مورد نظر كن بعد براي اوا دسته از چكباكس هاي مورد نظر - چك باكس زير رو بذار كه با انتخاب اون همه اونها انتخاب ميشد
<input type="checkbox" name="all_chk" value="true"onclick="checkUncheckAll(this);"//>SelectAll
اين هم فايل مورد نظر selectallcheckbox.js
function stripCharacter(words,character) {
var spaces = words.length;
for(var x = 1; x<spaces; ++x){
words = words.replace(character, "");
}
return words;
}
function changecss(theClass,element,value) {
var cssRules;
if (document.all) {
cssRules = 'rules';
}
else if (document.getElementById) {
cssRules = 'cssRules';
}
var added = false;
for (var S = 0; S < document.styleSheets.length; S++){
for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
if(document.styleSheets[S][cssRules][R].style[element]){
document.styleSheets[S][cssRules][R].style[element] = value;
added=true;
break;
}
}
}
if(!added){
if(document.styleSheets[S].insertRule){
document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
} else if (document.styleSheets[S].addRule) {
document.styleSheets[S].addRule(theClass,element+': '+value+';');
}
}
}
}
function checkUncheckAll(theElement) {
var theForm = theElement.form, z = 0;
for(z=0; z<theForm.length;z++){
if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
theForm[z].checked = theElement.checked;
}
}
}
function checkUncheckSome(controller,theElements) {
var formElements = theElements.split(',');
var theController = document.getElementById(controller);
for(var z=0; z<formElements.length;z++){
theItem = document.getElementById(formElements[z]);
if(theItem.type){
if (theItem.type=='checkbox') {
theItem.checked=theController.checked;
}
} else {
theInputs = theItem.getElementsByTagName('input');
for(var y=0; y<theInputs.length; y++){
if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id){
theInputs[y].checked = theController.checked;
}
}
}
}
}
function changeImgSize(objectId,newWidth,newHeight) {
imgString = 'theImg = document.getElementById("'+objectId+'")';
eval(imgString);
oldWidth = theImg.width;
oldHeight = theImg.height;
if(newWidth>0){
theImg.width = newWidth;
}
if(newHeight>0){
theImg.height = newHeight;
}
}
function changeColor(theObj,newColor){
eval('var theObject = document.getElementById("'+theObj+'")');
if(theObject.style.backgroundColor==null){theBG='w hite';}else{theBG=theObject.style.backgroundColor; }
if(theObject.style.color==null){theColor='black';} else{theColor=theObject.style.color;}
//alert(theObject.style.color+' '+theObject.style.backgroundColor);
switch(theColor){
case newColor:
switch(theBG){
case 'white':
theObject.style.color = 'black';
break;
case 'black':
theObject.style.color = 'white';
break;
default:
theObject.style.color = 'black';
break;
}
break;
default:
theObject.style.color = newColor;
break;
}
}
اين هم نحوه ضميمه كردنش
<script type="text/javascript" src="selectallcheckbox.js"></script>
این هم حق کپی رایت این پست : صلوات برای سلامتی و تعجیل در ظهور آقا صاحب الزمان علیه السلام
night star
دوشنبه 11 آبان 1388, 13:23 عصر
بنام خدا
كد جاواي زير رو مثلا بصورت فايل selectallcheckbox.js ذخيره و ضميمه صفحه مورد نظر كن بعد براي اوا دسته از چكباكس هاي مورد نظر - چك باكس زير رو بذار كه با انتخاب اون همه اونها انتخاب ميشد
منظورتون اینه که این چک باکس و بزارم واسه چک باکس اصلی (select all) , بقیه چک باکس هابا انتخاب این یکی انتخاب می شن ؟
یه سوال :این کدی که دادید واسه چک باکس واسه چک باکس های دیگه هم بزارم یا نه ، انها رو به صورت معمولی بنویسم من هر دو حالت و امتحان کردم ولی نشد
هواشناس
دوشنبه 11 آبان 1388, 13:36 عصر
بنام خدا
متن كاملتر
<script type="text/javascript" language="JavaScript">
function stripCharacter(words,character) {
var spaces = words.length;
for(var x = 1; x<spaces; ++x){
words = words.replace(character, "");
}
return words;
}
function changecss(theClass,element,value) {
var cssRules;
if (document.all) {
cssRules = 'rules';
}
else if (document.getElementById) {
cssRules = 'cssRules';
}
var added = false;
for (var S = 0; S < document.styleSheets.length; S++){
for (var R = 0; R < document.styleSheets[S][cssRules].length; R++) {
if (document.styleSheets[S][cssRules][R].selectorText == theClass) {
if(document.styleSheets[S][cssRules][R].style[element]){
document.styleSheets[S][cssRules][R].style[element] = value;
added=true;
break;
}
}
}
if(!added){
if(document.styleSheets[S].insertRule){
document.styleSheets[S].insertRule(theClass+' { '+element+': '+value+'; }',document.styleSheets[S][cssRules].length);
} else if (document.styleSheets[S].addRule) {
document.styleSheets[S].addRule(theClass,element+': '+value+';');
}
}
}
}
function checkUncheckAll(theElement) {
var theForm = theElement.form, z = 0;
for(z=0; z<theForm.length;z++){
if(theForm[z].type == 'checkbox' && theForm[z].name != 'checkall'){
theForm[z].checked = theElement.checked;
}
}
}
function checkUncheckSome(controller,theElements) {
var formElements = theElements.split(',');
var theController = document.getElementById(controller);
for(var z=0; z<formElements.length;z++){
theItem = document.getElementById(formElements[z]);
if(theItem.type){
if (theItem.type=='checkbox') {
theItem.checked=theController.checked;
}
} else {
theInputs = theItem.getElementsByTagName('input');
for(var y=0; y<theInputs.length; y++){
if(theInputs[y].type == 'checkbox' && theInputs[y].id != theController.id){
theInputs[y].checked = theController.checked;
}
}
}
}
}
function changeImgSize(objectId,newWidth,newHeight) {
imgString = 'theImg = document.getElementById("'+objectId+'")';
eval(imgString);
oldWidth = theImg.width;
oldHeight = theImg.height;
if(newWidth>0){
theImg.width = newWidth;
}
if(newHeight>0){
theImg.height = newHeight;
}
}
function changeColor(theObj,newColor){
eval('var theObject = document.getElementById("'+theObj+'")');
if(theObject.style.backgroundColor==null){theBG='w hite';}else{theBG=theObject.style.backgroundColor; }
if(theObject.style.color==null){theColor='black';} else{theColor=theObject.style.color;}
//alert(theObject.style.color+' '+theObject.style.backgroundColor);
switch(theColor){
case newColor:
switch(theBG){
case 'white':
theObject.style.color = 'black';
break;
case 'black':
theObject.style.color = 'white';
break;
default:
theObject.style.color = 'black';
break;
}
break;
default:
theObject.style.color = newColor;
break;
}
}
</script>
Form With Check all for select all chkbox in form
<form>
<input type="checkbox" name="all_chk" value="true"onclick="checkUncheckAll(this);"//>select all</span><hr />
<input name="chk1" type="checkbox" value="chk1-1" />chk1<br />
<input name="chk2" type="checkbox" value="chk1-2" />chk2<br />
<input name="chk3" type="checkbox" value="chk1-3" />chk3<br />
<input name="chk4" type="checkbox" value="chk1-4" />chk4<br />
<input name="chk5" type="checkbox" value="chk1-5" />chk5<br />
<input name="chk6" type="checkbox" value="chk1-6" />chk6<br />
<input name="chk7" type="checkbox" value="chk1-7" />chk7<br />
<input name="chk8" type="checkbox" value="chk1-8" />chk8<br />
<input name="chk9" type="checkbox" value="chk1-9" />chk9<br />
</form>
Form Without Check all
<form>
<input name="chk11" type="checkbox" value="chk2-1" />chk11<br />
<input name="chk21" type="checkbox" value="chk2-2" />chk21<br />
<input name="chk71" type="checkbox" value="chk2-7" />chk71<br />
<input name="chk81" type="checkbox" value="chk2-8" />chk81<br />
<input name="chk91" type="checkbox" value="chk2-9" />chk91<br />
</form>
night star
دوشنبه 11 آبان 1388, 13:49 عصر
مرسی درست شد فقط من موقعی که تو بانک insert می کنم تو یک رکورد ایجاد می شه راهی هست که بتوان هر کدوم از این چک باکس ها اطلاعاتش به طور جداگانه داخل یه رکورد بره
aryaei2000
دوشنبه 11 آبان 1388, 19:28 عصر
مرسی درست شد فقط من موقعی که تو بانک insert می کنم تو یک رکورد ایجاد می شه راهی هست که بتوان هر کدوم از این چک باکس ها اطلاعاتش به طور جداگانه داخل یه رکورد بره
من از این تکنیک استفاده میکنم.
برای همه ی چک باکس از کد زیر استفاده کن.
<input type="checkbox" name="CH1" value="true"onclick="checkUncheckAll(this);"//>SelectAll
بجز اون چک باکسی که با تیک خوردن بقیه تیک میخورن
If lcase(Request.ServerVariables("REQUEST_METHOD")) = "post" then
For each ch in Request.Form("CH1")
strCH = strCH & " OR Param = '" & ch & "'"
Next
If Len(strCH) > 0 then
strSQL = "INSERT INTO tblTest Where " & strCH & ";"
End If
موفق باشید.
vBulletin® v4.2.5, Copyright ©2000-1404, Jelsoft Enterprises Ltd.