www.webdeveloper.com
Recent Articles
  • Finding Slow Running Queries in ASE 15
  • A More Advanced Pie Chart for Analysis Services Data
  • Adobe AIR Programming Unleashed: Working with Windows
  • Performance Testing SQL Server 2008's Change Data Capture Functionality
  • The ABC's of PHP: Introduction to PHP
  • How to Migrate from BasicFiles to SecureFiles Storage
  • Why the Twitter Haters Are Wrong
  • User Personalization with PHP: Beginning the Application
  • Whats in an Oracle Schema?
  • Lighting Enhancement in Photoshop
  •  

    Go Back   WebDeveloper.com > Client-Side Development > JavaScript

    JavaScript JavaScript (not Java) Discussion and technical support, including AJAX and frameworks (JQuery, MooTools, Prototype...)

    Reply
     
    Thread Tools Search this Thread Rate Thread Display Modes
      #1  
    Old 11-25-2002, 05:31 PM
    ca_redwards's Avatar
    ca_redwards ca_redwards is offline
    Registered User
     
    Join Date: Nov 2002
    Location: Long Beach, CA
    Posts: 8
    Question When is a button array not a button array?

    I have created a pair of bookmarklets to implement a 100% pure JavaScript
    pop-up calendar. The first bookmarklet defines a library of HTML building
    functions for utilization by the second in building and displaying a pop-up
    calendar. This calendar has a hidden field to hold its date value, a
    drop-down list to select a different month, a textbox to enter a different
    year, and an array of buttons to select a different day of month. It is
    this button array that seems to have an intermittent problem with becoming mysteriously undefined.
    Initially, the calendar’s buttons are all blank and an opener window
    function labels them with the appropriate days of the month. This
    post-rendering technique works as designed. However, when I attempt to change the month, a JavaScript error implies that the button array is undefined. After dismissing the error dialog, the calendar renders okay for the new month.
    What is going on?
    Here are my two bookmarklets:
    Code:
    <a href="javascript:
    function Q(V){return' Q'+(V?('='+String.fromCharCode(34)+V+String.fromCharCode(34)):'')};
    function X(V){return'<X'+(V?V:'')+'>'};
    function Z(V){return'<Z'+(V?V:'')+'>'+this+'</'+'Z>'};
    function G(V){return'<G'+(V?V:'')+'>'+this.join('<G'+(V?V:'')+'>')};
    function R(V){return'<R'+(V?V:'')+'>'+this.join('</'+'R><R'+(V?V:'')+'>')+'</'+'R>'};
    String.prototype.gen=function gen()
    {var js='';var arr=this.split(' ');
    for(var i=0;i<arr.length;i++)
    {var t=arr[i];var T=t.toUpperCase();
    if(t==t.toLowerCase()){js+='window.'+T+'='+Q.toString().replace(/Q/g,T)+';'}
    else{if(t==T){js+='String.prototype.'+T+'='+Z.toString().replace(/Z/g,T)+';';
    js+='Array.prototype.'+T+'='+R.toString().replace(/R/g,T)+';'}
    else{js+='window.'+T+'='+X.toString().replace(/X/g,T)+';';
    js+='Array.prototype.'+T+'='+G.toString().replace(/G/g,T)+';'}};};
    eval(js);return this;};
    dhtml='A action align alt B background Base bgcolor BIG 
    BLINK BODY border bordercolor bordercolordark bordercolorlight Br cellpadding cellspacing checked color cols 
    colspan compact content dir DIV enctype face FONT FORM H1 
    H2 H3 H4 H5 H6 HEAD height Hr href hspace HTML I id Img 
    Input lang language leftmargin LI marginheight marginwidth 
    maxlength Meta method name NOSCRIPT noshade nowrap 
    OL onblur onchange onclick onfocus onload onmouseout 
    onmouseover onreset onselect onsubmit onunload OPTION P 
    PRE profile readonly rows rowspan SCRIPT SELECT size SMALL 
    SPAN src start STRIKE STYLE style SUB SUP TABLE target TD 
    TEXTAREA TH TITLE title topmargin TR TT type U UL valign 
    value vspace width wrap'.gen();
    window.status='HTML() bookmarklet library: Copyright (c) 2002, by Richard Edwards.';
    void(0);// dhtml: Copyright (c) 2002, by Richard Edwards.">HTML()</a>
    Code:
    <a href="javascript:
    m='January February March April May June July August September October November December'.split(' ');
    wd='Su M Tu W Th Fr Sa'.split(' ');  
    lom=[31,28,31,30,31,30,31,31,30,31,30,31];  
    sz=25;
    function getdate(F)
    {if(F.date.value){DATE=F.date.value.split('/');M=DATE[0]-1;D=DATE[1];Y=DATE[2]} 
    else{DATE=new Date();M=DATE.getMonth();D=DATE.getDate();Y=DATE.getFullYear()}; 
    lom[1]=28;
    if((Y% 4==0)&&((Y% 100>0)||(Y% 400==0))){lom[1]++};};
    function setdate(F){F.date.value=(1.0+M)+'/'+D+'/'+Y;}; 
    function render(F){alert(F.date.value)};
    function newday(){getdate(this.form);D=this.value;setdate(this.form);alert(this.form.date.value)};
    function newyear(){getdate(this.form);Y=this.value;setdate(this.form);render(this.form)};
    function newmonth(){getdate(this.form);M=this.selectedIndex;setdate(this.form);render(this.form)};
    window.render=function render(F)
    {if(!F)F=this.form; 
    getdate(F); f=new Date(Y,M,1);x=1-(f.getDay()); 
    for(i=0;i<49;i++){F.d[i].value=(i<7?wd[i]:'');
    F.d[i].onclick=this}; 
    for(i=1;i<=lom[M];i++){F.d[7+i-x].value=i;F.d[7+i-x].onclick=newday}; 
    for(i=0;i<m.length;i++){F.m[i].selected=(i==M);};
    F.m.onchange=newmonth; F.y.value=Y;F.y.onchange=newyear; 
    F.d[7+D-x].focus();
    setdate(F);};
    r=new Array(7).INPUT(TYPE('button')+NAME('d')+STYLE('width:'+sz+';height:'+sz)).TD(ALIGN('right')+WIDTH(sz*7)+HEIGHT(sz));
    h=m.OPTION().SELECT(NAME('m'))+INPUT(TYPE('text')+SIZE(4)+NAME('y'))+INPUT(TYPE('hidden')+NAME('date'));
    h=(h.TD(COLSPAN(7)+ALIGN('center')).TR()+[r,r,r,r,r,r,r].TR()).TABLE(BORDER('0')+CELLSPACING('0')+CELLPADDING('0')).FORM(NAME('frm'));  
    h+='opener.render(document.forms.frm);'.SCRIPT(TYPE('text/javascript'));
    window.open('','asdf','height='+sz*9+',width='+sz*8).document.write(h);
    void(0);// calendar: Copyright (c) 2002, by Richard Edwards.">calendar</a>
    __________________
    :Richard Edwards.

    Last edited by ca_redwards; 11-25-2002 at 07:26 PM.
    Reply With Quote
      #2  
    Old 11-25-2002, 07:10 PM
    gil davis's Avatar
    gil davis gil davis is offline
    Nobody important
     
    Join Date: Nov 2002
    Posts: 4,434
    Man! Did you look at this after you posted it?

    How about posting a link or fixing your post so that it isn't 50 feet wide.
    Reply With Quote
      #3  
    Old 11-25-2002, 07:22 PM
    ca_redwards's Avatar
    ca_redwards ca_redwards is offline
    Registered User
     
    Join Date: Nov 2002
    Location: Long Beach, CA
    Posts: 8
    Unhappy It's still "50 feet wide" ...

    Even after I edited it. The HTML() library's string of supported tags & attributes is very long! I'll break it up, I guess. But bookmarklets are supposed to be single lines of JavaScript code.

    These are each supposed to be one line.

    :Richard Edwards
    __________________
    :Richard Edwards.
    Reply With Quote
    Reply

    Bookmarks


    Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
     
    Thread Tools Search this Thread
    Search this Thread:

    Advanced Search
    Display Modes Rate This Thread
    Rate This Thread:

    Posting Rules
    You may not post new threads
    You may not post replies
    You may not post attachments
    You may not edit your posts

    BB code is On
    Smilies are On
    [IMG] code is Off
    HTML code is Off
    Forum Jump


    All times are GMT -5. The time now is 11:39 PM.



    Acceptable Use Policy

    internet.comMediabistrojusttechjobs.comGraphics.com

    WebMediaBrands Corporate Info


    Advertise | Newsletters | Feedback | Submit News

    Legal Notices | Licensing | Permissions | Privacy Policy

    Powered by vBulletin® Version 3.7.3
    Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.