0

I have two tables, table 1 with the fields of webID, project, web, and I use below PHP code(ThinkPHP framework) to get project list:

$project = M('WebProjectList')->where(array('web' => self::$web))->getField('project', true);

table 2 with the fields of userID, issue, web, project and I use below PHP code to get issue list:

$where['web'] = self::$web;
$where['project'] = array('in', $project);
$issue = M('UserIssue')->where($where)->group('issue')->getField('issue',true);

Below code in .js is the multiple-choice/checkbox of both projects and issues that let user choose, when user choose an issue which does not belong to that project, how to reminder user to check again before submitting?

$('.project2').each(function (index) {
    var project = result[index].project;
    for (var i in project) {
        var item = $('input[value="' + project[i] + '"]');
        $(this).find(item).attr('checked', 'checked');
    }
});


$('.issue2').each(function (index) {
    var issue = result[index].issue;
    for (var i in issue) {
        var item1 = $('input[value="' + issue[i] + '"]');
        $(this).find(item1).attr('checked', 'checked');
    }
});

And html code as below:

<th>Project</th>
<td>
    <div style="width: 800px" class="project2">
    <foreach name="projectlist" item="item">
        <label style="display: inline-block">
            <input type="checkbox" name="project" style="height: 18px;width: 18px" value="{$item}"/>
            {$item}&nbsp;&nbsp;
        </label>
    </foreach>
        <input type="checkbox" name="project" style="display: none" value="all" checked>
    </div>
</td>
</tr>


<tr>
<th>Issue</th>
<td>
    <div style="width: 800px" class="issue2">
    <foreach name="issueList" item="item1">
        <label style="display: inline-block">
            <input type="checkbox" name="issue" style="height: 18px;width: 18px" value="{$item1}"/>
            {$item1}&nbsp;&nbsp;
        </label>
    </foreach>
        <input type="checkbox" name="issue" style="display: none" value="all" checked>
    </div>
</td>
</tr>

and the actual html from inspect as below:

$('.project2').each(function(index) {
  var project = result[index].project;
  for (var i in project) {
    var item = $('input[value="' + project[i] + '"]');
    $(this).find(item).attr('checked', 'checked');
  }
});

$('.issue2').each(function(index) {
  var issue = result[index].issue;
  for (var i in issue) {
    var item1 = $('input[value="' + issue[i] + '"]');
    $(this).find(item1).attr('checked', 'checked');
  }
});
label {
  display: inline-block;
}

input[type=checkbox] {
  height: 18px;
  width: 18px;
}
<table>
  <tbody>
    <tr>
      <th>project</th>
      <td>
        <div style="width: 800px" class="project2">
          <label>
                <input type="checkbox" name="project[]" value="crosserver">
                crosserver&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="dev">
                dev&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="ceshi">
                ceshi&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="klfqios">
                klfqios&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="banshu">
                banshu&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="tishen">
                tishen&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="del">
                del&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="dyb">
                dyb&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="kuaiwan">
                kuaiwan&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="ddleios">
                ddleios&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="ybguios">
                ybguios&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="lgybios">
                lgybios&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="leboios">
                leboios&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="project[]" value="qpcios">
                qpcios&nbsp;&nbsp;
            </label>
          <input type="checkbox" name="project[]" value="all" checked="">
        </div>
      </td>
    </tr>


    <tr>
      <th>issue</th>
      <td>
        <div style="width: 800px" class="issue2">
          <label>
                <input type="checkbox" name="issue[]" value="cjsgios_lg">
                cjsgios_lg&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="dev">
                dev&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="dyb_msg">
                dyb_msg&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="dyb_msgios">
                dyb_msgios&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="dyb_testin_android">
                dyb_testin_android&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="dyb_wjlgz_android">
                dyb_wjlgz_android&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="huixie_banshu">
                huixie_banshu&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="kdmsios_jq">
                kdmsios_jq&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="kw_msg">
                kw_msg&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="unkonwn">
                unkonwn&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="wjlgzios_lg">
                wjlgzios_lg&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="zgtxios_ll">
                zgtxios_ll&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="zqsgios_Runhero">
                zqsgios_Runhero&nbsp;&nbsp;
            </label>
          <label>
                <input type="checkbox" name="issue[]" value="{4ff036a1-3254eafe}">
                {4ff036a1-3254eafe}&nbsp;&nbsp;
            </label>
          <input type="checkbox" name="issue[]" value="all" checked="">
        </div>
      </td>
    </tr>
  </tbody>
</table>
David Thomas
  • 249,100
  • 51
  • 377
  • 410
Elsa
  • 1
  • 1
  • 8
  • 27
  • 2
    Can you provide some HTML markup that has been produced by your PHP script? – Carsten Massmann Sep 09 '20 at 16:41
  • @cars10m Hi, I've already updated it, thanks for reading my question. – Elsa Sep 10 '20 at 00:35
  • 1
    The `` element is obviously not a standard HTML element, so I have to assume you're using a framework? If so could you please add that framework to your list of tags? You've edited your question to show what emerges from PHP but - given the presence of an apparent templating framework - you still haven't shown the HTML that is the end-result. Could you please post a snippet of the generated HTML once it's been fully rendered, processed and put on the client's page? There *probably* won't be any `` or `{$item1}` or similar in the end result. Take a look at "*[mcve]*" guide. – David Thomas Sep 10 '20 at 00:45
  • @DavidsaysreinstateMonica It's ThinkPHP framework – Elsa Sep 10 '20 at 01:49
  • ... and, as @DavidsaysreinstateMonica mentioned: try and grab the generated HTML from your browser. You should go to the developer tools, "inspect" each table, "edit HTML" and copy and paste the markup for us (at least an excerpt of those tables). – Carsten Massmann Sep 10 '20 at 04:43
  • 2
    @cars10m hi, I edited again, thanks for your time for reading my question. – Elsa Sep 10 '20 at 06:22
  • @FIRE: thank you for the edit and update, taking the code you've posted I've tried to put together a Snippet (a runnable example of your code) from the code you've added to the question. Unfortunately it still crashes because `result` is not defined, would you be able to declare/initialise that variable for us so we can see how your code functions? I'm sorry that we appear to be pestering you for constant changes, but we need enough of your code - in a runnable/accurate representation - to reproduce your problem or situation. – David Thomas Sep 10 '20 at 09:14

0 Answers0