mercredi 24 décembre 2014

Cancel HREF when checking a checkbox inside the

I have a css drop down menu:



<ul>
<li>
<a href="http://myurl.com">
Sample Text
<div>
<label><input type="checkbox" name="pub" /></label>
</div>
</a>
</li>
</ul>


and the following javascript:



$(function()
{
$("input[name='pub']").parent()
.change(function(event)
{
//...
});
});


Everytime the checkbox is clicked the href of the "a" is fired because of the "input" is inside of the "a"... There's a way to detect who is clicked, "input" or "a" when i check the checkbox and cancel the href??





trigger css animation with checkbox inside a fieldset

I try to trigger an animation only when a checkbox is checked. I have the following code :



<div data-role="fieldcontain" >
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="checkbox" class="mediaCheckbox" id="playCheck"/>
<label data-role="button" class="fa fa-play" id="play" for="playCheck"></label>
<input type="checkbox" class="mediaCheckbox" id="muteCheck"/>
<label data-role="button" class="fa fa-bell" id="mute" for="muteCheck"></label>
</fieldset>
</div>
<div id="stuffToAnimate"></div>


and the following css :



#stuffToAnimate {
position: relative;
-webkit-animation: ball 11s ease-in-out 0s infinite normal; /* Chrome, Safari, Opera */
-webkit-animation-play-state: paused;
}
#playCheck:checked **XXX**{
-webkit-animation-play-state: running;
}

@-webkit-keyframes ball {
0% {top:5%;}
40% {-webkit-transform: rotate(0deg);}
50% {-webkit-transform: rotate(180deg);top:80%;}
90% {-webkit-transform: rotate(180deg);}
100% {-webkit-transform: rotate(360deg);top:5%;}
}


My problem is : How to complete the XXX selector in order to trigger the animation. I could put the checkbox #playCheck in the same level as #stuffToAnimate, but it would mess up my presentation.





Iterate through custom ListView to save checked checkboxes and spinners

I have Activity A that runs Activity B with a button click.


Activity B has a list view with custom rows:


some rows have a title and checkboxes.


and some rows have a title and a spinner .


each row the user either checks the preferred checkboxes or chooses from a spinner.


so far so good. my problem is , when clicking back to Activity A, how do I save all the choices? and by save I don't mean just save his checked boxes but also get the values of his choices back to Activity A.


I don't want the choices to be saved even after I restart the app. only when the app is running .


So basically I need to : 1. get the user's choices and save their values (either from a spinner or from the checkbox) 2. save the ticked checkboxes the next time the user clicks to go to activity B


I thought about using onPause in Activity B , where I will get a reference to the listView, go through every row, see if there is a checkbox or a spinner there, and then somehow see what value is checked (if its checkboxes) and what value is selected(if its a spinner).


I don't know if it's the right approach or not, anyway I really need help here.





Show selected checkbox values using javascript

I have been trying to create checkboxes and show their values. When you try to select only one of them, it works. When you try to select more than one, it only shows the highest value selected. How can I show all the values of all selected checkboxes?


Here is the code so far:


Html:



<!doctype html>
<html>
<head>
<title>Javascript checkboxes in real time</title>
<link rel = "stylesheet" href = "css/default.css">
</head>
<body>
<form action = "" method = "post">
<input type="checkbox" id = "1" value = "1">1<br>
<input type="checkbox" id = "2" value = "2">2<br>
<input type="checkbox" id = "3" value = "3">3<br>
<input type="checkbox" id = "4" value = "4">4<br>
<input type="checkbox" id = "5" value = "5">5<br>
</form>
<section></section>
<script src = "js/default.js"></script>
</body>
</html>


Javascript:



var checkbox = document.getElementsByTagName('input');
var section = document.getElementsByTagName('section');

setInterval(function(){
for(var i = 0; i <= checkbox.length - 1; i++){
if(checkbox[i].checked){
section[0].innerHTML = checkbox[i].value;
break;
}
else{
section[0].innerHTML = null;
}
}
}, 10);




How to call new JSON AsynTask() in the Adapter's getView() on CheckBox click?

I know the JSON parsing. I have A List View and Grid View in same Activity. My List View has Check Box. So I am getting it's click in adapter class. So when I check that Check Box, then A new JSON will call and the data will set in the Grid View. But when I am trying to call the new JSON on setOnCheckedChangeListener(). then I am getting “System services not available to Activities before onCreate()” in onPostExecute().


Here is my code.



checkBox.setOnCheckedChangeListener(new OnCheckedChangeListener() {

@Override
public void onCheckedChanged(CompoundButton buttonView,
boolean isChecked) {

ac = new PhoneAndTabletsActivity();
ac.new SendFilterInfo().execute();


}
});


In postExecute()



@Override
protected void onPostExecute(Void result) {
super.onPostExecute(result);
phoneTabletAdapter = new PhoneAndTabletAdapter1(
PhoneAndTabletsActivity.this,
R.layout.row_phone_and_tablet1, filterArray);
gridView.setAdapter(phoneTabletAdapter);
}




How to detect a checkbox click in jQuery

I cannot detect when and which checkbox gets clicked from script below:


HTML Snippet:



<label for="checkbox[1]"><input type="checkbox" name="checkbox[1]" id="checkbox[1]" class="detectThisChange" value="10.00" checked=""> Amount $10.00</label>
<label for="checkbox[2]"><input type="checkbox" name="checkbox[2]" id="checkbox[2]" class="detectThisChange" value="20.00" checked=""> Amount $20.00</label>
<label for="checkbox[3]"><input type="checkbox" name="checkbox[3]" id="checkbox[3]" class="detectThisChange" value="30.00" checked=""> Amount $30.00</label>


jQuery Snippet:



$('.detectThisChange').change(function(event){
var targetID = triggerEvent.target.id; // get the id that triggered the event
var posStart = targetID.indexOf('[') + 1;
var posEnd = targetID.indexOf(']');
var i = targetID.substring(posStart, posEnd); // get the index of the id that triggered the event

if ( $('#checkbox\\['+ i +'\\]').prop('checked') != true ) {
alert('checkbox ' + i + ' was checked');
}
else {
alert('checkbox ' + i + ' was unchecked');
}

});




PHP, checkbox which returns multiple values (rows)

I have a table with some attributes and I need a checkbox in every row. This table is shown to users and they can check some rows. At least one row should be checked, but there is no limit of how many of them can be checked, all checkboxes can be checked. When user chooses some rows, I need to get two attributes of every selected row - date and id. After that I need to have these attributes in an array, where I can reach them like this:



echo $pole[0]; --> output: 1.12.2014
echo $pole[1]; --> output: 4
echo $pole[2]; --> output: 5.12.2014
echo $pole[3]; --> output: 8


Here's my code:



session_start();
include('connect.php');

$stmt = $db->query('SELECT * FROM tabulka');

foreach($stmt as $row)
{
echo "<tr>";
echo "<td>" . $row['date'] . "</td>";
echo "<td>" . $row['city'] . "</td>";
echo "<td>" . $row['id'] . "</td>";
echo "<td>" . $row['deadline'] . "</td>";
echo "<td> <input type=\"checkbox\" name=\"interest[]\" value=\"" . $row['date'] . " " . $row['id'] . " " . "\"></td>";
}


The last echo creates a checkbox in every row of the table, but I'm not sure, if it's correct. When user chooses some rows and press the submit button it goes to another file:



session_start();

if(isset($_POST['submit'])) {//to run PHP script on submit
if (!empty($_POST['interest'])) {
$data = $_POST['interest'];
foreach ($data as $selected) {
echo $selected."</br>";
}


This works, but I can't reach those attributes as I want to. I tried to split $data, but it hasn't worked. I can only reach a char of the array or the whole row (date and id, but not only date or only id).


Can someone help, please? Also if there is a better solution, I'd be grateful.


BTW: Merry Christmas stackoverflowers !!