SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Help filling array

    This is part of a js script that I want to be able to update some how. I dont care if the body is kept in a db or in a file, but I have no idea where to start with this. Heres the part of interest:
    Code:
    // THE CONTENT - ['href','text','target']
    n_content=[
    ['','Sales Consultant<br/>Jasmine Wyber<br/>Areas: Nation Wide<br/>Contact: 0274-851-1221',''],
    ['','Stanmore Rd Auto Spares<br/>Areas: Nation Wide<br/>Contact: 0221-221-221',''],
    ['','Dyers Rd Timber<br/>Areas: Canterbury',''],
    ['','Harvey Normans<br/>Areas: Nation Wide','']
    ];
    It is the text areas that I want to be able to update. href and target dont matter at this point.

    Heres the complete file if you want to put it into an html file to see how it works:
    Code:
    /* 
    USE WORDWRAP AND MAXIMIZE THE WINDOW TO SEE THIS FILE
    ========================================
    NewsBar v1.4
    License : Freeware (Enjoy it!)
    (c)2004 VASIL DINKOV- PLOVDIV, BULGARIA
    ========================================
    For IE4+, NS4+, Opera7+ & Konqueror2+
    ========================================
    Get the NewsBar script at:
    http://www.smartmenus.org/other.php
    and don't wait to get the Great SmartMenus script at:
    http://www.smartmenus.org
    LEAVE THESE NOTES PLEASE - delete the comments if you want 
    */
    // BUG in Opera:
    // If you want to be able to control the body margins
    // put the script right after the BODY tag, not in the HEAD!!!
    // === 1 === FONT, COLORS, EXTRAS...
    n_font='verdana,arial,sans-serif';
    n_fontSize='10px';
    n_fontSizeNS4='11px';
    n_fontWeight='normal';
    n_fontColor='silver'; //#4A49A8
    n_textDecoration='none';
    n_fontColorHover='#ff0000';//				| won't work
    n_textDecorationHover='underline';//		| in Netscape4
    n_bgColor='transparent';//set [='transparent'] for transparent#DEDFF6
    n_top=200;//		|
    n_left=630;//		| defining
    n_width=250;//		| the box
    n_height=75;//		|
    n_position='absolute';// absolute/relative
    n_timeOut=10;//seconds
    n_pauseOnMouseOver=true;
    n_speed=100;//1000 = 1 second
    n_leadingSign='_';
    n_alternativeHTML='Exactfx Advertising Systems';
    // for not supported browsers like Opera<7 - usually
    // you may want to put a link to your news page 
    // === 2 === THE CONTENT - ['href','text','target']
    //['http://www.smartmenus.org/other.php','You can always get the latest version at: //http://www.smartmenus.org/other.php','_self'],
    n_content=[
    ['','Sales Consultant<br/>Jasmine Wyber<br/>Areas: Nation Wide<br/>Contact: 0274-851-1221',''],
    ['','Stanmore Rd Auto Spares<br/>Areas: Nation Wide<br/>Contact: 0221-221-221',''],
    ['','Dyers Rd Timber<br/>Areas: Canterbury',''],
    ['','Harvey Normans<br/>Areas: Nation Wide','']
    ];
    // THE SERIOUS SCRIPT - PLEASE DO NOT TOUCH
    n_nS4=document.layers?1:0;n_iE=document.all&&!window.innerWidth&&navigator.userAgent.indexOf("MSIE")!=-1?1:0;n_nSkN=document.getElementById&&(navigator.userAgent.indexOf("Opera")==-1||document.body.innerHTML)&&!n_iE?1:0;n_t=0;n_cur=0;n_l=n_content[0][1].length;n_timeOut*=1000;n_fontSize2=n_nS4&&navigator.platform.toLowerCase().indexOf("win")!=-1?n_fontSizeNS4:n_fontSize;document.write('<style>.nnewsbar,a.nnewsbar,a.nnewsbar:visited,a.nnewsbar:active{font-family:'+n_font+';font-size:'+n_fontSize2+';color:'+n_fontColor+';text-decoration:'+n_textDecoration+';font-weight:'+n_fontWeight+'}a.nnewsbar:hover{color:'+n_fontColorHover+';text-decoration:'+n_textDecorationHover+'}</style>');n_p=n_pauseOnMouseOver?" onmouseover=clearTimeout(n_TIM) onmouseout=n_TIM=setTimeout('n_new()',"+n_timeOut+")>":">";n_k=n_nS4?"":" style=text-decoration:none;color:"+n_fontColor;function n_new(){if(!(n_iE||n_nSkN||n_nS4))return;var O,mes;O=n_iE?document.all['nnewsb']:n_nS4?document.layers['n_container']
    .document.layers['nnewsb']:document.getElementById('nnewsb');mes=n_content[n_t][0]!=""&&n_cur==n_l?("<a href='"+n_content[n_t][0]+"' target='"+n_content[n_t][2]+"' class=nnewsbar"+n_p+n_content[n_t][1].substring(0,n_cur)+n_leadingSign+"</a>"):("<span class=nnewsbar"+n_k+">"+n_content[n_t][1].substring(0,n_cur)+n_leadingSign+"</span>");if(n_nS4)with(O.document){open();write(mes);close()}else O.innerHTML=mes;if(n_cur++==n_l){n_cur=0;n_TIM=setTimeout("n_new()",n_timeOut);n_t++;if(n_t==n_content.length)n_t=0;n_l=n_content[n_t][1].length}else{setTimeout("n_new()",n_speed)}};document.write('<div '+(n_nS4?"name":"id")+'=n_container style="position:'+n_position+';top:'+n_top+'px;left:'+n_left+'px;width:'+n_width+'px;height:'+n_height+'px;clip:rect(0,'+n_width+','+n_height+',0)"><div '+(n_nS4?"name":"id")+'=nnewsb style="position:absolute;top:0px;left:0px;width:'+n_width+';height:'+n_height+'px;clip:rect(0,'+n_width+','+n_height+',0);background-color:'+n_bgColor+';
    layer-background-color:'+n_bgColor+';text-decoration:none;color:'+n_fontColor+'" class=nnewsbar>'+n_alternativeHTML+'</div></div>');if(!n_nS4)setTimeout("n_new()",1000);else window.onload=n_new;if(n_nS4)onresize=function(){location.reload()}
    Where it says : // THE SERIOUS SCRIPT - PLEASE DO NOT TOUCH
    It must be all on one line from that point on.
    Any help/guidelines appreciated.

  2. #2
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    Where is the relavence to PHP?
    Ian Anderson
    www.siteguru.co.uk

  3. #3
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I was thinking of storing the info in a db as one possibility and using php to do my selects and to fill in the required content (text).

    I know nothing about js, but I doubt I could use it to insert new info and update the script as required.

    ['',$business<br/>Areas: $area,'']

    I dont know if its possible to combine php within js, but I cant see why not. By using php I can use a form so that anyone can update the file/db.

  4. #4
    SitePoint Member
    Join Date
    Feb 2004
    Location
    Italy,turin
    Posts
    15
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    you could create a sql table to store your link info (href,target ect) .
    you could save your file with php extension and generate your js array dynamicly
    querying your table.
    and then include your php in your page head.
    hidran
    www.photoviaggi.com
    pictures from around the world

  5. #5
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I have no trouble with the db part,but the script runs like it is typing, then hesitates for 30sec. This is why I included the complete script, so some-one could see what it is I'm dealing with.

    Will I still be able to fill the array with it having a typing effect and use a loop with it hesitating all the time.

    Thanks for your help.

  6. #6
    SitePoint Wizard siteguru's Avatar
    Join Date
    Oct 2002
    Location
    Scotland
    Posts
    3,631
    Mentioned
    2 Post(s)
    Tagged
    0 Thread(s)
    PHP runs before anything is sent to the client. JavaScript runs on the client. Basically, PHP would create the entire JS code and echo it to the browser, then the browser would act on it.

    i.e. If you are able to type in the JS code and save it as a text file then call it in a web page, then PHP can also do it.

    The difference would be if you are dynamically changing the JS array ON THE CLIENT SIDE - you would need to find some way to replicate those changes into your DB.
    Ian Anderson
    www.siteguru.co.uk

  7. #7
    SitePoint Guru
    Join Date
    Feb 2002
    Location
    NZ
    Posts
    620
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    OK, can some-one suggest the easiest way to update this js file, form using php, or is there something else.

    Thanks for the answers guys


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
  •