开发者

In Extjs, How do I see if a checkbox is checked, and then if it is checked, add that checkboxes id to an array?

I am learning Extjs along with PHP and MySQL for one of my web development course in college right now, and I am very close to finishing my final project for the class and I am stuck on something as simple as a checkbox. I am more into c# programming, so my c# mindset is clashing with the necessities of ExtJS.

The program asks hospital patients a vast amount of questions about their day-to-day feelings, and I have a list of Checkboxes for common symptoms and I need to be able to check to see, once they submit the form, which symptoms were checked and add that symptoms id to the symptoms array.

Is this even close?

    if(headacheCheckbox.getValue()==true){
        symptoms[headacheCheckbox.getId()];
    }

on the Server Side I have

        $id=$dbh->lastInsertId();
        $symptom=$_REQUEST['symptoms'];
        while($tmp=$symptom->fetch()){
        $stmt=$dbh->prepare("insert into symptom_input (inputid, symptomid) values (?,?)");
    开发者_Python百科    $stmt->bindParam(1, $id);
        $stmt->bindParam(2, $tmp);
        $stmt->execute();
        }

and I have my ajax request in my ExtJS taking in the symptom array as a parameter like so..

    params: {action: 'create_input',
        symptoms: symptoms[],
        },

Absolutely any help/criticism is welcome.

Thank You!


This line

 $symptom=$_REQUEST['symptoms'];

and this line

 while($tmp=$symptom->fetch()){

do not compute.

fecth is method ffor prepared statement object http://il2.php.net/manual/en/mysqli-stmt.fetch.php (when you fetchign a result set, similar to mysql_fecth_row for unprepared statements) while you have an array parsed to this variable $symptom=$_REQUEST['symptoms']; So your fetch will throw an error in while

assuming that your array looks like this

$_REQUEST['symptoms'][112];
$_REQUEST['symptoms'][234];

what you need is something like this

  $id=$dbh->lastInsertId();
  $symptom=$_REQUEST['symptoms'];

   foreach($symptoms as $symptomid){
        $stmt=$dbh->prepare("insert into symptom_input (inputid, symptomid) values (?,?)");
        $stmt->bindParam(1, $id);
        $stmt->bindParam(2, $symptomid);
        $stmt->execute();
        }

Also when passing a parameters

assuming that code bellow is creating an array in your JavaScript

if(headacheCheckbox.getValue()==true){
        symptoms[headacheCheckbox.getId()];
    }

you need to

params: {action: 'create_input',
        symptoms: symptoms //without square brackets and no comma IE7 will throw an error
        },
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜