Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i have 4 check box

  <input type="checkbox" name="1" id="1" data-toggle="toggle" data-onstyle="default"  data-width="500%" >
  <input type="checkbox" name="2" id="2" data-toggle="toggle" data-onstyle="default"  data-width="500%" >
  <input type="checkbox" name="3" id="3" data-toggle="toggle" data-onstyle="default"  data-width="500%" >
  <input type="checkbox" name="4" id="4" data-toggle="toggle" data-onstyle="default"  data-width="500%" >

i want if some one "check" a check box ajax send the id of that check box and {0,1} depend on if checked then 1 , if unchecked 0 to a php script via post asap its checked or unchecked

 <?php
    if($_POST['id'] && $_POST['state'])
    {
    $id = $_POST['id'];
    $state= $_POST['state'];

    print $id;
    print $state;
    }
    ?>

some thing like this.

if checbox1 == checked:
       post(checkbox1[id],1)
if(checkbox1== unchecked)
       post(checkbox1[id],0)

how can i do this,

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
262 views
Welcome To Ask or Share your Answers For Others

1 Answer

no jquery:

function task(e)
{
  
  if(e.target.checked)
  {
    ///do post request with 1 in parameter
    console.log("do post request with 1 in parameter");
  }
  else
  {
    ///do post request with 0 parameter
    console.log("do post request with 0 parameter");
  }
}
<input type="checkbox" onclick="task(event);"/>

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share

548k questions

547k answers

4 comments

86.3k users

...