-3

I have a jquery function..

*function isCheckedById(id) {
  var checked = $("input[@id=" + id + "]:checked").length;

  if (checked == 0) {
    return false;
  }

else {
    return true;
  }
}*

And I want to use return the value of this function in my php code..

if ("checked") // checked
{

echo '<input type="checkbox" name="'.$brand_item->name.'" value="'.$brand_item->slug.'" checked><label for="'.$brand_item->term_id.'">'.$brand_item->slug.'</label>';

                    }

Help me, what parameter should I give to If statement so that I can use the value return by my jquery function. I am using these codes in wordpress, Please explain in details as I am completely new to these things.

  • 2
    Possible duplicate of [What is the difference between client-side and server-side programming?](http://stackoverflow.com/questions/13840429/what-is-the-difference-between-client-side-and-server-side-programming) – Epodax Jun 16 '16 at 06:30
  • Try and use `ajax` – Apoorv Jun 16 '16 at 06:54

1 Answers1

0

You can do something like in your template file:

function isCheckedById(id) {
  var checked = $("input[@id=" + id + "]:checked").length;
  var html = '';
  if (checked == 0) {
    return false;
  }

else {
    return true;
  }
}

if(isCheckedById('checkit')){

    html = '<input type="checkbox" name="<?php echo $brand_item->name; ?>" value="<?php echo $brand_item->slug; ?>" checked><label for="<?php echo $brand_item->term_id; ?>"><?php echo $brand_item->slug; ?></label>';
    $('#container').html(html);
}