www.webdeveloper.com
Results 1 to 3 of 3

Thread: [RESOLVED] Beginner needs simple help

  1. #1
    Join Date
    Sep 2009
    Posts
    2

    resolved [RESOLVED] Beginner needs simple help

    Hi I am new to javascript and was wondering if someone could help me with a pretty basic idea.

    What I want to create is a list of items, with a button at the top, and when you click the button, you get a prompt, and if you type in an item that is matchable on the list, then that item on the list will be striked out.

    And so you could have a list of 50 items and each time you enter a valid item into the prompt it will cross the corresponding item out on the list.

    So for example if you had a list of girls you wanted to kiss before you die you could make a list of all their names and then as you accomplish each goal you could push the button and type their name in the prompt, and the script would strike their name out on the list.

    Here is a visual example of what I mean:

    http://i104.photobucket.com/albums/m176/jozsefs/eg.jpg

    Could anyone give me the basic gist of how I would create such a script? Keeping in mind that I am a beginner

  2. #2
    Join Date
    Jun 2004
    Location
    Portsmouth UK
    Posts
    2,662
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
        "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    
    <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
    
    <head>
      <title></title>
    <script type="text/javascript">
    /*<![CDATA[*/
    
    function Strik(obj){
     var p=prompt('Strik')
     while (obj.nodeName!='UL'&&obj.parentNode){
      obj=obj.parentNode;
     }
     var lis=obj.getElementsByTagName('LI');
     for (var z0=0;z0<lis.length;z0++){
      if (lis[z0].innerHTML.replace(/\s/g,'')==p){
       lis[z0].style.textDecoration='line-through';
      }
     }
    
    }
    /*]]>*/
    </script></head>
    
    <body>
    <ul>
      <li><input type="button" name="" value="Strik" onclick="Strik(this);"/></li>
      <li>tom</li>
      <li>dick</li>
      <li>harry</li>
    </ul>
    </body>
    
    </html>
    Vic

    God loves you and will never love you less.

    http://www.vicsjavascripts.org/Home.htm
    If my post has been useful please donate to http://www.operationsmile.org.uk/

  3. #3
    Join Date
    Sep 2009
    Posts
    2
    Oh wow you didn't just help you wrote up the code for me!

    Thank you vwphillips, I'm sorry to come in here asking for help with such basic stuff, but I read over a crapload of javascript tutorial first and learned some of what I needed but hit a wall and was looking for someone to send me in the right direction again.

    But you went above and beyond and just did the code for me. I really appreciate it. By the way if you are curious, I am going to use the code for a little personal project I am working on, when I am done it will have about 500 items in non-alphabetical order in 5 different columns and that little tool you gave me will allow me to rapidly and repeatedly mark individual items off the list with ease without needing to manually search through the hundreds of items.

    I will PM the finished product here so you can see what I used your tool to do

    Thank you so much you are a very kind person

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles