Refresh values with a button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • FrogyWill

    Refresh values with a button

    Hi
    Below is a great script I found to make charts.
    The value are in form objects. I am changing the hidden fields to drop down
    list with multiple values, so that the users can choose what data will be
    used.

    So I need a "button" to refresh the graph. I understand I need a function to
    refresh the script. I don't know much about javascipts... Can anybody here
    help me? Thanks a lot :)

    Script:

    <HTML><HEAD>

    <!-- Cut-N-Paste JavaScript from ISN Toolbox
    Copyright 1996, Infohiway, Inc. Restricted use is hereby
    granted (commercial and personal OK) so long as this code
    is not *directly* sold and the copyright notice is buried
    somewhere deep in your HTML document. A link to our site
    http://www.infohiway.com is always appreciated of course,
    but is absolutely and positively not necessary. ;-) -->

    <SCRIPT LANGUAGE="JavaS cript">
    <!--

    function getHplot(){
    n=new initArray(0,0,0 ,0,0,0)
    v=new initArray(0,0,0 ,0,0,0)
    title=document. isnform.title.v alue;
    stitle=document .isnform.stitle .value;
    document.write( '<TABLE BORDER=0 WIDTH=486><TR>< TD '
    +'COLSPAN=3 ALIGN=CENTER><B >Horizontal Bar Graph</'
    +'B></TD></TR><TR><TD COLSPAN=3 ALIGN=CENTER><B >'
    +title+'</B><BR><I>'+stit le+'</I></TD></TR>');
    v[0]=document.isnfo rm.v1.value;
    v[1]=document.isnfo rm.v2.value;
    v[2]=document.isnfo rm.v3.value;
    v[3]=document.isnfo rm.v4.value;
    v[4]=document.isnfo rm.v5.value;
    v[5]=document.isnfo rm.v6.value;
    n[9]=0;
    n[6]=0;
    n[7]=0;
    for (var i=0;i<6;i++){
    if (v[i].length>n[9]){
    n[9]=v[i].length;
    }

    str=v[i]
    StringToNumber( );
    n[i]=num; // eval(v[i]); may be substituted
    if (n[i]<0){
    n[i]=0;
    }
    n[6]+=n[i];
    if (n[i]>n[7]){
    n[7]=n[i];
    }
    }
    n[10]=(n[9]+6)*8
    n[8]=n[7]/(484-n[10]); // my divisor
    document.write( '<TR><TD><B>'+d ocument.isnform .n1.value
    +'</B></TD><TD><IMG SRC="a.gif" HEIGHT=10 WIDTH='
    +(n[0]/n[8])+' BORDER=1></TD><TD>'+v[0]+'</TD></TR>'
    +'<TR><TD><B>'+ document.isnfor m.n2.value
    +'</B></TD><TD><IMG SRC="b.gif" HEIGHT=10 WIDTH='+(n[1]/n[8])
    +' BORDER=1></TD><TD>'+v[1]+'</TD></TR>'
    +'<TR><TD><B>'+ document.isnfor m.n3.value
    +'</B></TD><TD><IMG SRC="c.gif" HEIGHT=10 WIDTH='+(n[2]/n[8])
    +' BORDER=1></TD><TD>'+v[2]+'</TD></TR>'
    +'<TR><TD><B>'+ document.isnfor m.n4.value
    +'</B></TD><TD><IMG SRC="d.gif" HEIGHT=10 WIDTH='+(n[3]/n[8])
    +' BORDER=1></TD><TD>'+v[3]+'</TD></TR>'
    +'<TR><TD><B>'+ document.isnfor m.n5.value
    +'</B></TD><TD><IMG SRC="e.gif" HEIGHT=10 WIDTH='+(n[4]/n[8])
    +' BORDER=1></TD><TD>'+v[4]+'</TD></TR>'
    +'<TR><TD><B>'+ document.isnfor m.n6.value
    +'</B></TD><TD><IMG SRC="a.gif" HEIGHT=10 WIDTH='+(n[5]/n[8])
    +' BORDER=1></TD><TD>'+v[5]+'</TD></TR>');
    document.write( '<TR><TD COLSPAN=3><HR NOSHADE></TD></TR></TABLE>');
    getVplot();
    }

    function getVplot(){
    n[8]=n[7]/100;
    document.write( '<P><TABLE BORDER=0 WIDTH=486><TR>< TD'
    +' COLSPAN=6 ALIGN=CENTER><B >Vertical Bar Graph</B></TD></TR>'
    +'<TR><TD COLSPAN=6 ALIGN=CENTER><B >'
    +title+'</B><BR><I>'+stit le+'</I></TD></TR><TR>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER><I MG SRC="a.gif" HEIGHT='
    +(n[0]/n[8])
    +' WIDTH=50 BORDER=1></TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER><I MG SRC="b.gif" HEIGHT='
    +(n[1]/n[8])+' WIDTH=50 BORDER=1></TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER><I MG SRC="c.gif" HEIGHT='
    +(n[2]/n[8])+' WIDTH=50 BORDER=1></TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER><I MG SRC="d.gif" HEIGHT='
    +(n[3]/n[8])+' WIDTH=50 BORDER=1></TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER><I MG SRC="e.gif" HEIGHT='
    +(n[4]/n[8])+' WIDTH=50 BORDER=1></TD>'
    +'<TD VALIGN=BOTTOM ALIGN=CENTER><I MG SRC="a.gif" HEIGHT='
    +(n[5]/n[8])+' WIDTH=50 BORDER=1></TD></TR><TR>'
    +'<TD ALIGN=CENTER><B >'+document.isn form.n1.value+' </B></TD>'
    +'<TD ALIGN=CENTER><B >'+document.isn form.n2.value+' </B></TD>'
    +'<TD ALIGN=CENTER><B >'+document.isn form.n3.value+' </B></TD>'
    +'<TD ALIGN=CENTER><B >'+document.isn form.n4.value+' </B></TD>'
    +'<TD ALIGN=CENTER><B >'+document.isn form.n5.value+' </B></TD>'
    +'<TD ALIGN=CENTER><B >'+document.isn form.n6.value+' </B></TD></TR>'
    +'<TR><TD ALIGN=CENTER>'+ v[0]+'</B></TD>'
    +'<TD ALIGN=CENTER>'+ v[1]+'</TD>'
    +'<TD ALIGN=CENTER>'+ v[2]+'</TD>'
    +'<TD ALIGN=CENTER>'+ v[3]+'</TD>'
    +'<TD ALIGN=CENTER>'+ v[4]+'</TD>'
    +'<TD ALIGN=CENTER>'+ v[5]+'</TD></TR><TR><TD COLSPAN=6'
    +'><HR NOSHADE><P></TD></TR></TABLE>');
    }
    var pwr=new initArray(1,2,3 ,4);
    pwr[0]=1;
    pwr[1]=10;
    pwr[2]=100;
    pwr[3]=1000;
    pwr[4]=10000;
    pwr[5]=100000;
    pwr[6]=1000000;
    pwr[7]=10000000;
    /* Add more to array - pwr[8]=100000000, etc. -
    if strings longer than 8 are to be used. */
    var ns="0123456789 "
    var cr="";
    var str="";

    function StringToNumber( ){
    num=0;
    strl=str.length ;
    for (var j=strl-1;j>-1;j--){
    cr=str.substrin g(j,j+1);
    pos=ns.indexOf( cr);
    num+=pos*pwr[strl-j-1];
    }
    }

    function initArray() {
    this.length=ini tArray.argument s.length;
    for (var i=0;i<this.leng th;i++) {
    this[i]=initArray.argu ments[i];
    }
    }

    -->
    </SCRIPT>

    <BODY BGCOLOR="#FFFFF F">

    <FORM NAME='isnform'>

    <INPUT TYPE='hidden' NAME='title' VALUE='chart title'>
    <INPUT TYPE='hidden' NAME='stitle' SIZE='40' VALUE='subtitle '>


    <INPUT TYPE='hidden' NAME='n1' SIZE='8' VALUE='29/6-6/7'>
    <INPUT TYPE='hidden' NAME='n2' SIZE='8' VALUE='6/7-13/7'>
    <INPUT TYPE='hidden' NAME='n3' SIZE='8' VALUE='13/7-20/7'>
    <INPUT TYPE='hidden' NAME='n4' SIZE='8' VALUE='20/7-27/7'>
    <INPUT TYPE='hidden' NAME='n5' SIZE='8' VALUE='27/7-31/7'>
    <INPUT TYPE='hidden' NAME='n6' SIZE='8' VALUE='29/6-31/7'>

    <INPUT TYPE='hidden' NAME='v1' SIZE='8' VALUE='100.00'>
    <INPUT TYPE='hidden' NAME='v2' SIZE='8' VALUE='43.54'>
    <INPUT TYPE='hidden' NAME='v3' SIZE='8' VALUE='75.55'>
    <INPUT TYPE='hidden' NAME='v4' SIZE='8' VALUE='71.57'>
    <INPUT TYPE='hidden' NAME='v5' SIZE='8' VALUE='77.56'>
    <INPUT TYPE='hidden' NAME='v6' SIZE='8' VALUE='25.57'>
    </FORM>

    <SCRIPT LANGUAGE="JavaS cript">
    <!--

    getHplot();

    -->
    </SCRIPT>
    </body>
    </HTML>





  • Lasse Reichstein Nielsen

    #2
    Re: Refresh values with a button

    "FrogyWill" <frogy_97@hotma il.com> writes:
    [color=blue]
    > Below is a great script I found to make charts.[/color]

    .... for some definition of "great" :)
    It's obviosuly not a new script, and not very well written either.
    That doesn't mean that the output isn't great :)
    [color=blue]
    > The value are in form objects. I am changing the hidden fields to drop down
    > list with multiple values, so that the users can choose what data will be
    > used.[/color]
    [color=blue]
    > So I need a "button" to refresh the graph. I understand I need a function to
    > refresh the script.[/color]

    This is a problem. The graph is written to the page using "document.write ".
    That only works well while the page is being loaded. If you try to use
    document.write later, you will erase the current page.

    You will have to use another way of adding the graph to an existing
    page. Which method depends on which browsers you need to support (new
    browsers have DOM methods for creating content, old browsers, like
    Netscape 4, doesn't). You'll have to decide.
    /L
    --
    Lasse Reichstein Nielsen - lrn@hotpop.com
    Art D'HTML: <URL:http://www.infimum.dk/HTML/randomArtSplit. html>
    'Faith without judgement merely degrades the spirit divine.'

    Comment

    Working...