Results 1 to 3 of 3

Thread: Please write a simple javascript code for me

  1. #1
    Join Date
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Unhappy Please write a simple javascript code for me

    Hello
    Please write the javascript code for me :S
    want to have 37 buttons numbered and ordered from 0 to 36 (0;1;2;3;4;5;...33;34;35;36)
    If I click one of them it must become at the first position of the list.
    for example at first list is ordered from 0 to 36: 0;1;2;3;4;5;...33;34;35;36
    then, after I click button 4, it becomes the first at list: 4;0;1;2;3;5;...33;34;35;36
    then, after I click button 34, it becomes the first at list: 34;4;0;1;2;3;5;...33;35;36
    after this If I click button 35, the list will become: 35;34;4;0;1;2;3;5;...33;36
    and so on..
    Please write it for me :S

  2. #2
    Join Date
    Dec 2008
    Location
    Portsmouth, UK
    Posts
    1,891
    Thanks
    2
    Thanked 441 Times in 435 Posts

    Default

    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>
    </head>
    <body>
    <input class="button" type="button" name="" value="Button 1" />
    <input class="button" type="button" name="" value="Button 2" />
    <input class="button" type="button" name="" value="Button 3" />
    <input class="button" type="button" name="" value="Button 4" />
    <br />
    <input class="button" type="button" name="" value="Button 5" />
    <input class="button" type="button" name="" value="Button 6" />
    <input class="button" type="button" name="" value="Button 7" />
    <input class="button" type="button" name="" value="Button 8" />
    <br />
    <input class="button" type="button" name="" value="Button 9" />
    <input class="button" type="button" name="" value="Button 10" />
    <input class="button" type="button" name="" value="Button 11" />
    <input class="button" type="button" name="" value="Button 12" />
    <input class="button" type="button" name="" value="Button 13" />
    <input class="button" type="button" name="" value="Button 14" />
    <input class="button" type="button" name="" value="Button 15" />
    <br />
    <input class="button" type="button" name="" value="Button 16" />
    <input class="button" type="button" name="" value="Button 17" />
    <input class="button" type="button" name="" value="Button 18" />
    <input class="button" type="button" name="" value="Button 19" />
    <br />
    <input class="button" type="button" name="" value="Button 20" />
    <input class="button" type="button" name="" value="Button 21" />
    <input class="button" type="button" name="" value="Button 22" />
    <input class="button" type="button" name="" value="Button 23" />
    <input class="button" type="button" name="" value="Button 24" />
    <input class="button" type="button" name="" value="Button 25" />
    <br />
    <input class="button" type="button" name="" value="Button 26" />
    <input class="button" type="button" name="" value="Button 27" />
    <input class="button" type="button" name="" value="Button 28" />
    <input class="button" type="button" name="" value="Button 29" />
    <br />
    <input class="button" type="button" name="" value="Button 30" />
    <input class="button" type="button" name="" value="Button 31" />
    <input class="button" type="button" name="" value="Button 32" />
    <input class="button" type="button" name="" value="Button 33" />
    <input class="button" type="button" name="" value="Button 34" />
    <input class="button" type="button" name="" value="Button 35" />
    <br />
    <input class="button" type="button" name="" value="Button 36" />
    <input class="button" type="button" name="" value="Button 37" />
    
    
    <script  type="text/javascript">
    /*<![CDATA[*/
    
    var zxcSwapButton={
    
     init:function(cls){
      var ary=this.bycls(cls,document),a=[],o={},z0=0;
      o.ary=ary;
      o.lks=[];
      for (var z0=0;z0<ary.length;z0++){
       a=document.createElement('A');
       o.lks[z0]=a;
       ary[z0].parentNode.insertBefore(a,ary[z0]);
       this.addevt(ary[z0],'mouseup','insert',o,ary[z0]);
      }
     },
    
     insert:function(o,obj){
      for (var mve,z0=0,z1=0;z0<o.ary.length;z0++){
       if (o.ary[z0]==obj){
        o.ary.splice(z0,1);
        break;
       }
      }
      o.ary=[obj].concat(o.ary);
      for (;z1<o.lks.length;z1++){
       o.lks[z1].parentNode.insertBefore(o.ary[z1],o.lks[z1]);
      }
     },
    
     addevt:function(o,t,f,p,p1){
      var oop=this;
      if (o.addEventListener) o.addEventListener(t,function(e){ return oop[f](p,p1);}, false);
      else if (o.attachEvent) o.attachEvent('on'+t,function(e){ return oop[f](p,p1); });
     },
    
     bycls:function (nme,el){
      for (var reg=new RegExp('\\W'+nme+'\\W'),els=el.getElementsByTagName('*'),ary=[],z0=0; z0<els.length;z0++){
       if(reg.test(' '+els[z0].className+' ')){
        ary.push(els[z0]);
       }
      }
      return ary;
     }
    
    }
    
    zxcSwapButton.init('button');
    /*]]>*/
    </script>
    </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
    Jun 2012
    Posts
    2
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Smile Thank you very much!

    Thank you very much! You helped me a lot! god bless you!

Bookmarks

Posting Permissions

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