• Resolved erpico57

    (@erpico57)


    Dear all,

    First, i am an “absolute beginner” in WP, coming from classic HTML static sites.
    In shortly, i would like to re-build in WP a little part running in the homepage of the current HTML-site.

    In this homepage, my JS provides to extract the actual zodiacal period (a text, eg. “Fishes”), the corresponding zodiacal stone (again a text, eg. “Amethyst”) and the related picture (in this case the path, eg. …/imgpietre/Amethyst.png).

    If i write the same function calls in my WP-homepage (in textmode) as in my HTML-page, the system shows the right zodiacal period
    and zodiacal stone (therefore, the script is running right or at least, the JS-call is working right).
    Unfortunately it doesn’t show the image (i only see the typical empty square).

    I suppose, the syntax of the following function call is not working in the WP-homepage or WP-environment like in the static HTML page.
    The syntax i use is:

    <body onLoad=”avvia()” lang=”it”>

    where the row above comes immediately after </head> closing
    and i couldn’t find any solution to realize in another way this call (of course, if this is the right problem ).

    Probably, I don’t consider other important things working in WP.

    Perhaps could you give me any advice or see any basically error using these component in WP ?

    I don’t ask you about a solution, only having a track to work in the right way!
    I can provide JS and HTML-homepage to analyse this issue if needed.

    Thank you very much in advance for your appreciated cooperation.

    Regards

    Ernesto

    My actual environment:

    – Windows 7 Professional
    – WordPress: V. 4.2.2
    – Xampp: 3.2.2
    – WP theme: Catch Evolution (entry version)
    – Child theme: created with plugin “child-theme-configurator.1.7.9.1” and actually in use

Viewing 5 replies - 1 through 5 (of 5 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    You should be able to tell what’s wrong through the browser’s console – which I assume you’ve been using to develop the JS. Chrome’s console, for example, can accessed by pressing F12

    Thread Starter erpico57

    (@erpico57)

    Hy Andrew,

    Ok, i’m not very familiarized with this kind of tools…
    I’m working sometimes with Firebug. If i open it, i see an error like:

    X TypeError: nuovo[conta] is undefined
    document.galle.src=nuovo[conta]

    but this info was already known.

    Sorry but i don’t know how can i help you to show where is the bug…

    Follow you can see the script, perhaps it can help you to understand what happens:

    var period;
    var zodiac;
    var sign;
    var pietra;
    var filepath;

    // function to extract the actual zodiacal period
    function getPeriod()
    {
    var oggi = new Date();
    var gior = oggi.getDate().toString();
    var mese = (oggi.getMonth() + 1).toString();
    var anno = oggi.getFullYear().toString();
    var data = anno + ( mese.length < 2 ? “0” : “” ) + mese + ( gior.length < 2 ? “0” : “” ) + gior;

    if ( parseInt( data ) >= parseInt( anno + “0320” ) && parseInt( data ) <= parseInt( anno + “0420” ) ) { // dal 20 marzo al 20 aprile
    document.write(“dell’Ariete ” ); sign = 0; pietra = “il Diaspro rosso”; filepath = “Pietre_ariete.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0421” ) && parseInt( data ) <= parseInt( anno + “0519” ) ) { // dal 21 aprile al 19 maggio
    document.write(” del Toro” ); sign = 1; pietra = “il Quarzo rosa”; filepath = “Pietre_toro.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0520” ) && parseInt( data ) <= parseInt( anno + “0621” ) ) { // dal 20 maggio al 21 giugno
    document.write(“dei Gemelli” ); sign = 2; pietra = “l´Occhio di tigre”; filepath = “Pietre_gemelli.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0622” ) && parseInt( data ) <= parseInt( anno + “0722” ) ) { // dal 22 giugno al 22 luglio
    document.write(“del Cancro”); sign = 3; pietra = “la Pietra di Luna”; filepath = “Pietre_cancro.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0723” ) && parseInt( data ) <= parseInt( anno + “0822” ) ) { // dal 23 luglio al 22 agosto
    document.write(“del Leone”); sign = 4; pietra = “il Cristallo di rocca”; filepath = “Pietre_leone.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0823” ) && parseInt( data ) <= parseInt( anno + “0923” ) ) { // dal 23 agosto al 23 settembre
    document.write(“della Vergine”); sign = 5; pietra = “l´Amazzonite”; filepath = “Pietre_vergine.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0924” ) && parseInt( data ) <= parseInt( anno + “1022” ) ) { // dal 24 settembre al 22 ottobre
    document.write(“della Bilancia”); sign = 6; pietra = “la Giada”; filepath = “Pietre_bilancia.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “1023” ) && parseInt( data ) <= parseInt( anno + “1121” ) ) { // dal 23 ottobre al 21 novembre
    document.write(“dello Scorpione”); sign = 7; pietra = “il Quarzo tormalinato”; filepath = “Pietre_scorpione.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “1122” ) && parseInt( data ) <= parseInt( anno + “1221” ) ) { // dal 22 novembre al 21 dicembre
    document.write(“del Sagittario”); sign = 8; pietra = “la Malachite”; filepath = “Pietre_sagittario.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “1222” ) && parseInt( data ) <= parseInt( anno + “3112” ) ) { // dal 22 dicembre al 31 dicembre,
    document.write(“del Capricorno”); sign = 9; pietra = “l´Ossidiana”; filepath = “Pietre_capricorno.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0101” ) && parseInt( data ) <= parseInt( anno + “0120” ) ) { // dal 1° gennaio al 20 gennaio
    document.write(“del Capricorno”); sign = 9; pietra = “l´Ossidiana”; filepath = “Pietre_capricorno.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0121” ) && parseInt( data ) <= parseInt( anno + “0219” ) ) { // dal 21 gennaio al 19 febbraio
    document.write(“dell’Acquario”); sign = 10; pietra = “il Lapislazzuli”; filepath = “Pietre_acquario.htm”;
    }
    if ( parseInt( data ) >= parseInt( anno + “0220” ) && parseInt( data ) <= parseInt( anno + “0319” ) ) { // dal 20 febbraio al 19 marzo
    document.write(“dei Pesci”); sign = 11; pietra = “l´Ametista”; filepath = “Pietre_pesci.htm”;
    }
    }

    // define array with all zodiacal stones used
    function apri(conta) {
    nuovo=new Array(“imgpietre/diaspro_rosso_ariete.png”,”imgpietre/quarzo_rosa_toro.png”,”imgpietre/occhio_di_tigre_gemelli.png”,”imgpietre/pietre_di_luna_cancro.png”,
    “imgpietre/cristallo_di_rocca_leone.png”,”imgpietre/amazzonite_vergine.png”,”imgpietre/giada_bilancia.png”, “imgpietre/quarzotormalinato_scorpione.png”,
    “imgpietre/malachite_sagittario.png”,”imgpietre/ossidiana_capricorno.png”,”imgpietre/lapislazzulo_acquario.png”,”imgpietre/ametista_pesci.png”)
    document.galle.src=nuovo[conta]

    }

    // function for the assembling the <href> statement to display the image and the corresponding file path pointing on a html page which contains more information about stones of this zodiacal sign

    function getlink() {
    document.write(‘‘);
    document.write(‘<img src=”” name=”galle” class=”pietra” height=92 width=123 />’);
    }

    // Function to start the JS into the home page of the site
    function avvia() {
    apri(sign)
    }

    // Function to extract the corresponding zodiacal stone
    function getStone() {
    stone= pietra;
    document.write(stone);
    }

    Let me know if you need further information!

    Thank you very much!

    Regards
    Ernesto

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Would it be okay if you could try to replicate the issue on jsFiddle: https://jsfiddle.net/ ? You might discover what the issue is in the process too.

    Thread Starter erpico57

    (@erpico57)

    Thanks a lot Andrew !!

    I will give you a feedback ASAP.

    Bye

    Ernesto

    Thread Starter erpico57

    (@erpico57)

    Hello Andrew,

    i could solve the issue! A part of the problem was a wrong call in function.php and the other part the path!

    Thank you very much for your tip!

    Ernesto

Viewing 5 replies - 1 through 5 (of 5 total)
  • The topic ‘JavaSript – one of the functions does not work in WP’ is closed to new replies.