Strikethrough text by JavaScript string object

Using JavaScript string object strikethrough property we can develop a todo list with checkbox associated with each task or line of text. Based on the checkbox is clicked or not we can strike the line of text . Here we will use javascript strike through string object.
We will also use checkbox onClick event to trigger the JavaScript function to mark as del for the text.

strikethrogh task list

Here is the code of above demo
<!doctype html public "-//w3c//dtd html 3.2//en">
<html>
<head>
<title>Demo of Strikethrough JavaScript string object</title>
<script type="text/javascript">
function my_fun(j){
var chkbox ="ckb" + j;
var my_span ="my_span" + j;
var msg = chkbox + "  " + my_span;
if(document.getElementById(chkbox).checked){ 
document.getElementById(my_span).style.textDecoration='line-through';
}else{
document.getElementById(my_span).style.textDecoration='none';
}
}
</script>
</head>
<body>

<form name=form1 method=post action=check.php>
<input type=checkbox  id=ckb1 value=1 onclick=my_fun(1);><span id='my_span1'>This is job number 1</span>  <br>
<input type=checkbox  id=ckb2 value=2 onclick=my_fun(2);><span id='my_span2'>This is job number 2</span>  <br>
<input type=checkbox  id=ckb3 value=3 onclick=my_fun(3);><span id='my_span3'>This is job number 3</span>  <br>
</form>
</body>
</html>

JavaScript String Reference Lowercase to Upper case by toUpperCase() method
Subscribe to our YouTube Channel here


Subscribe

* indicates required
Subscribe to plus2net

    plus2net.com







    Sudhir

    22-09-2012

    if i want to check all/ unchecked all then how to work check box for Strikethrough text in javascript
    Kiran

    06-10-2012

    Given in a short & simple manner, this is what i am looking for Thank you to the author
    stan

    09-08-2013

    Thanks for this!
    Daniele

    26-01-2014

    Is there a possibility to have the browser to persistently save the action of strikethrogh?

    Thank you for your time
    smo1234

    27-01-2014

    Yest it is possible, we can use Ajax with any server side script to update database.

    Post your comments , suggestion , error , requirements etc here




    We use cookies to improve your browsing experience. . Learn more
    HTML MySQL PHP JavaScript ASP Photoshop Articles FORUM . Contact us
    ©2000-2024 plus2net.com All rights reserved worldwide Privacy Policy Disclaimer