THis in your loop
echo "<input type=\"checkbox\" name =\"confirm[$k]\" value=\"{$data[$k][0]}\" />";
Set up js listener to check for 'confirm' check events. This will append the value of the checkbox to the textbox text. E.g. for all browsers other than IE (need attachEvent for that).
document.forms['myform'].elements['confirm'].addEventListener('click',do-your-function-name-here,false)
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
I understood your post, I just didn't want to do all the work for you. You can add the 'value' (e-mail address) of the checked checkbox to the textbox.
document.forms['myform'].elements['mytextbox'].value = document.forms['myform'].elements['mytextbox'].value + ", " + passedVariable;
Check this, my js isn't too hot.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
OK, seeing as you had a good go yourself. I'm using the jQuery library here, so if you copy this exactly, it should work in all browsers.
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"></script>
<script>
$(document).ready(function() {
$( "input[name='check[]']" ).bind( "click", clickCheck )
function clickCheck(){
var str = $("#txt").val();
var newStr = $(this).val();
if($(this).is(':checked')){
$("#txt").val(str + newStr + ",");
}else{
$("#txt").val(str.replace(newStr + ',', ''));
}
}
});
</script>
</head>
<body>
<form name="myform" id="myform">
<input type="checkbox" value="a1@fictic.io.us" name="check[]" id="check1" /><label for="check1">a1@fictic.io.us</label>
<input type="checkbox" value="a2@fictic.io.us" name="check[]" id="check2" /><label for="check2">a2@fictic.io.us</label>
<input type="checkbox" value="a3@fictic.io.us" name="check[]" id="check3" /><label for="check3">a3@fictic.io.us</label>
<input type="checkbox" value="a4@fictic.io.us" name="check[]" id="check4" /><label for="check4">a4@fictic.io.us</label>
<input type="text" value="" name="txt" id="txt" />
</form>
</body>
It's slightly different from my previous post. I found that applying an email_id to the name attribute of the checkbox was unnecessary.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
php to read from the file.
jquery to deal with the add/subtract.
just change to this:
<form name="myform">
<table border="1" cellspacing="0" cellpadding="0" align="center" width="25%">
<tr><td align="center"><input type="text" name="txt" size="50" ></td></tr>
<?php
$userinfo = file("sometext_file");
foreach($userinfo as $key => $val){
$data[$key] = explode("||", $val);
}
for($k = 0; $k < sizeof($userinfo); $k++){
?>
<tr bgcolor="#ffffff"><td><input type="checkbox" id="check_<?php echo $k;?>" name ="check[]" value="<?php echo $data[$k][0];?>" /><label for="check_<?php echo $k;?>"><?php echo $data[$k][0];?></label></td></tr>
<?php
}
?>
</table>
</form>
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080
OK if it works, mark this thread solved.
diafol
Rhod Gilbert Fan (ardav)
7,800 posts since Oct 2006
Reputation Points: 1,170
Solved Threads: 1,080