dongyue110702 2014-07-15 05:20
浏览 49
已采纳

Codeigniter:试图获得非对象的属性

I have a condition in javascript that says if the text box is blank it would alert and return false, but it doesn't work instead it submits here is my view

frm_otherequips2.php

<form action="edit_delete_others2" method="POST" id='frm_otherequips2' name="frm_otherequips2">
    <fieldset id="edit_other">
        <legend>Inventory Details</legend>
        <table>
            <tr>
                <?php $otherequips = $other->Equipment;
                      $otherdesc = $other->ItemDescription;
                      $otherID = $other->ID;
                      $otherserialnum = $other->SerialNumber;
                ?>
                <td>Equipment</td>
                <td><input type="text" id="txt_editotherequip" name="txt_editotherequip" value="<?php echo $otherequips ?>"/></td>
                <td>Item Description</td>
                <td><input type="text" id="txt_editotherdesc" name="txt_editotherdesc" value="<?php echo $otherdesc ?>"/></td>
                <td style="visibility: hidden;"><input type="text" id="txt_editotherID" name="txt_editotherID" value="<?php echo $otherID ?>"/></td>
            </tr>
            <tr>
                <td>Serial Number</td>
                <td><input type="text" id="txt_editotherserialnum" name="txt_editotherserialnum" value="<?php echo $otherserialnum ?>"/></td>
            </tr>
            <tr>
                <td><button class="btn_editother" id="btn_editother" name="btn_editother" type="submit" value="Edit" onclick="validate_edit_otherequip();">Edit</button></td>
            </tr>
        </table>
    </fieldset>
</form>

and here is my javascript:

    <script>

    function validate_edit_otherequip(){
        if(document.getElementById('txt_editotherequip').value === ""){
            alert('Please Input Equipment!');
            return false;
        }
        else if(document.getElementById('txt_editotherdesc').value === ""){
            alert('Please Input Item Description');
            return false;
        }
        else if(document.getElementById('txt_editotherserialnum').value === ""){
            alert('Please Input Serial Number');
            return false;
        }
        else{
            var y;
            if(confirm("Are you sure you want to save updated data?") === true){
                var y = document.forms['frm_otherequips2'].submit();
            }
            else if(confirm("Are you sure you want to save updated data?") === false){
                return false;
            }
        }
    }
</script>

What I did is i put return false in controller, here is my controller:

public function edit_delete_others2($id){
        $data_other['other'] = $this->inventory_model->other_search($id);
        $this->load->view('homeview');
        $this->load->view('frm_otherequips2', $data_other);
        $this->load->view('footer_view');


        if(!empty($_POST['btn_editother'])){
            if($_POST['txt_editotherequip'] == "") {
                return false;
            }
            else if($_POST['txt_editotherdesc'] == "") {
                return false;
            }
            else if($_POST['txt_editotherserialnum'] == ""){
                return false;
            }
            else{
                 $this->inventory_model->update_others($this->input->post());
                 redirect('inventorysys_controller/view_others', 'refresh');
            }

    }
}

But everytime i run it and I leave a blank textbox for example 'txt_editotherequip' is blank it posts the alert and then this error occur:

**A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/frm_otherequips2.php

Line Number: 10

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/frm_otherequips2.php

Line Number: 11

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/frm_otherequips2.php

Line Number: 12

A PHP Error was encountered

Severity: Notice

Message: Trying to get property of non-object

Filename: views/frm_otherequips2.php

Line Number: 13**

Please do help me on this one, I've been stuck with this for days. Thank you in advance for your help!

  • 写回答

2条回答 默认 最新

  • drl57959 2014-07-15 06:15
    关注

    Make sure that the onclick event occurs, since you said that the form submits whereas in your code it should have popped up a confirm box or an alert on any case.

    function validate_edit_otherequip(){
        alert('works!');
        ....
    }
    

    Check for javascript errors.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?
  • ¥15 c++头文件不能识别CDialog