مشکل با چک باکس ها

mohammad_1ta

Active Member
سلام دوستان،
خسته نباشید...

یه فرم ساختم که یه مشکلی داره...

فایل ضمیمه رو دانلود کنین و بازش کنین.

اگه روی شماره 3 بزنین، گزینه 1 - 2 غیرفعال میشه.
میخوام شماره های دیگش هم همین خاصیت رو داشته باشه... یعنی 1 رو بزنیم، 2 و 3 غیرفعال بشه.
ولی نمیشه :green:


کد نویسیش ظاهراً درسته ها... ولی عمل نمیکنه :-?:sad:

ممنون میشم بگین چطوری درستش کنم.
 

پیوست ها

  • 1.zip
    803 بایت · بازدیدها: 6

aghanaser

Member
پاسخ

باسلام
دوست عزيز به نظر من اشكال كار در استفاده از تابع شرطي else هست.
به جاي استفاده از else دستور if را تكرار كنيد.
به اين صورت كه :

PHP:
if(checkname1.checked)
{
	test1.checked="false";
	test2.checked="false";
	test3.checked="true";
	test4.checked="true";
}
if(checkname2.checked)
{
	test1.checked="true";
	test2.checked="true";
	test3.checked="false";
	test4.checked="false";
}
يك هم چين چيزي ديگه....:-?
 

mohammad_1ta

Active Member
ممنون...

اینطوری هم تست کردم.
نتیجش این بود که اگه گزینه 1 تیک بخره، دیگه روی گزینه 2 یا 3 نمیشه کلیک کرد. (یعنی Disable نیستا ولی کلیک هم نمیشه کرد) :cry:
 

maxpelank

Active Member
با سلام

مشکل شما رو حل کردم :

مشکلات زیادی داشت

- درست بکار نبردن نام چک باکس ها
- استفاده از چک باکس به جای رادیو باکس
- درست نگرفتن باکس با جاوا اسکریپت
مواردفوق رو درست کردم و مشکل رو حل کردم :

کد:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>

<body>




<SCRIPT LANGUAGE="JavaScript">
    function CheckStatus(Formname,rowid){
        //reset
        if(rowid == 0){
            for (i=0; i<Formname.rahnamayi.length; i++){
                Formname.rahnamayi[i].disabled = true;
                Formname.rahnamayi[i].checked = false;
            }
            for (i=0; i<Formname.dabirestan.length; i++){
                Formname.dabirestan[i].disabled = true;
                Formname.dabirestan[i].checked = false;
            }
            for (i=0; i<Formname.ebtedayi.length; i++){
                Formname.ebtedayi[i].disabled = true;
                Formname.ebtedayi[i].checked = false;
            }
        
        }
        
        if(rowid == 1){
            for (i=0; i<Formname.rahnamayi.length; i++){
                Formname.rahnamayi[i].disabled = true;
                Formname.rahnamayi[i].checked = false;
            }
            for (i=0; i<Formname.dabirestan.length; i++){
                Formname.dabirestan[i].disabled = true;
                Formname.dabirestan[i].checked = false;
            }
            for (i=0; i<Formname.ebtedayi.length; i++){
                Formname.ebtedayi[i].disabled = false;
            }
        
        }
        if(rowid == 2){
            for (i=0; i<Formname.rahnamayi.length; i++){
                Formname.rahnamayi[i].disabled = false;
            }
            for (i=0; i<Formname.dabirestan.length; i++){
                Formname.dabirestan[i].disabled = true;
                Formname.dabirestan[i].checked = false;
            }
            for (i=0; i<Formname.ebtedayi.length; i++){
                Formname.ebtedayi[i].disabled = true;
                Formname.ebtedayi[i].checked = false;
            }
        
        }
        if(rowid == 3){
            for (i=0; i<Formname.rahnamayi.length; i++){
                Formname.rahnamayi[i].disabled = true;
                Formname.rahnamayi[i].checked = false;
            }
            for (i=0; i<Formname.dabirestan.length; i++){
                Formname.dabirestan[i].disabled = false;
            }
            for (i=0; i<Formname.ebtedayi.length; i++){
                Formname.ebtedayi[i].disabled = true;
                Formname.ebtedayi[i].checked = false;
            }
        
        }
   }
</SCRIPT>



<table width="100%" border="0" cellpadding="0" cellspacing="0">
<form id="addnews2" name="addnews2" method="post" action="">
    <tr style="padding-top: 10px;">
        <td width="25%"><input type="radio" name="maghta" value="ebtedayi" onClick="CheckStatus(this.form,'1');" >  <B>ebtedayi</B></td>
        <td width="25%"><input type="checkbox" name="ebtedayi" id="allow_now1" value="A" disabled="disabled"/> A</td>
        <td width="25%"><input type="checkbox" name="ebtedayi" id="allow_now2" value="B" disabled="disabled"/> B</td>
        <td width="25%"><input type="checkbox" name="ebtedayi" id="allow_now3" value="C" disabled="disabled"/> C</td>
    </tr>
    <tr style="padding-top: 10px;">
        <td width="25%"><input type="radio" name="maghta" value="rahnamayi" onClick="CheckStatus(this.form,'2');" >  <B>rahnamayi</B></td>
        <td width="25%"><input type="checkbox" name="rahnamayi" id="allow_now4" value="D" disabled="disabled"/> D</td>
        <td width="25%"><input type="checkbox" name="rahnamayi" id="allow_now5" value="E" disabled="disabled"/> E</td>
        <td width="25%"><input type="checkbox" name="rahnamayi" id="allow_now6" value="F" disabled="disabled"/> F</td>
    </tr>
    <tr style="padding-top: 10px;">
        <td width="25%"><input type="radio" name="maghta" value="dabirestan" onClick="CheckStatus(this.form,'3');" >  <B>dabirestan</B></td>
        <td width="25%"><input type="checkbox" name="dabirestan" id="allow_now7" value="G" disabled="disabled" /> G</td>
        <td width="25%"><input type="checkbox" name="dabirestan" id="allow_now8" value="H" disabled="disabled"/> H</td>
        <td width="25%"><input type="checkbox" name="dabirestan" id="allow_now9" value="I" disabled="disabled"/> I</td>
    </tr>
    <input type="reset" value="reset" name="resetb" onClick="CheckStatus(this.form,'0');"/>
</form>


</body>
</html>

منابع استافده شده :
کد:
http://www.javascriptkit.com/jsref/checkbox.shtml

کد:
http://www.hscripts.com/tutorials/javascript/dom/checkbox-events.php


موفق باشید
 

جدیدترین ارسال ها

بالا