Home:ALL Converter>Javascript - Select checkbox by value

Javascript - Select checkbox by value

Ask Time:2012-10-23T22:07:00         Author:brunotiago

Json Formatter

I made this code to select one checkbox when I click on a image but this don't work.

$linkToInterview = 'checkById(document.myform.checkbox,$interview_id)';
?>
<a href="javascript:void(0);" onclick='<?=$linkToInterview?>'><img src="<?=siteConfig::img_dir?>new_photos/video.gif" style="border:0px"/></a>

And Javascript function:

<script type="text/javascript">
function checkByID(chk,id) {
chk[id].checked = true ;
}
</script>

And checkbox code:

<td><input type="checkbox" name="checkbox" value="<?php echo $fet['id']; ?>"

Author:brunotiago,eproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/13032328/javascript-select-checkbox-by-value
Passerby :

$linkToInterview = 'checkById(document.myform.checkbox,$interview_id)';\n\n\nwill contain literal $interview_id, which means you're outputting\n\n<a href=\"...\" onclick='checkById(document.myform.checkbox,$interview_id)'>\n\n\nTo contain the content of $interview_id, you should use double quote, add a single quote around it, and use double quote on HTML output:\n\n<?php\n$linkToInterview = \"checkById(document.myform.checkbox,'$interview_id')\";\n?>\n<a href=\"...\" onclick=\"<?=$linkToInterview?>;\">\n\n\nThis will output (assuming your $interview_id=\"test\"):\n\n<a href=\"...\" onclick=\"checkById(document.myform.checkbox,'test');\">\n",
2012-10-24T07:53:54
yy