A function that uses JavaScript to remove spaces at both ends of a string

Source: Internet
Author: User

Function trim (STR)
{
VaR S = STR;
VaR I, Len;
VaR hasempty = false;
If (S. charat (0) = "")
{
S = S. Replace ("","");
Hasempty = true;
}
Len = S. length;
If (S. charat (len-1) = "")
{
S = S. Replace ("","");
Hasempty = true;
}
If (hasempty = true)
{
S = trim (s );
}
Else
{
Return S;
}
}

<HTML>
<Head>
<Title> pie chart </title>
<SCRIPT>
Function drawpiechart ()
{
VaR totalvalue = value1.value/360 + value2.value/360 + value3.value/360 + value4.value/360;
VaR Per1 = value1.value/totalvalue;
VaR per2 = value2.value/totalvalue;
VaR per3 = value3.value/totalvalue;
VaR per4 = value4.value/totalvalue;

VaR per12 = Per1 + per2;
VaR per123 = Per1 + per2 + per3;

Chart. innerhtml = "<Object ID = 'piechar' classid = 'clsid: 2017303c2-d7ac-11d0-89d5-00a0c90833e6 'style = 'position: relative; top: 0; left: 0; width: 400; height: 400 '> <Param name = 'line0001' alue = 'setlinecolor (255, 0,127) '> <Param name = 'line0002' value = 'setfillstyle (1) '> <Param name = 'line0003' value = 'setfillcolor (0,255, 80)'> <Param name = 'line0004' value = 'pie (-100,-100,200,200, 0, "+ Per1 +", 0) '> <Param name = 'line0005' value = 'setfillstyle (1) '> <Param name = 'line0006' value = 'setfillcolor (0, 0,255) '> <Param name = 'line0007' value = 'pie (-100,-100,200,200, "+ Per1 +", "+ per2 +", 0) '> <Param name = 'line0008' value = 'setfillstyle (1)'> <Param name = 'line0009' value = 'setfillcolor (0,128,128) '> <Param name = 'line0010' value = 'pie (-100,-100,200,200, "+ per12 +", "+ per3 +", 0) '> <Param name = 'line0011' value = 'setfillstyle (1)'> <Param name = 'line0012 'value = 'setfillcolor (255, 0, 0) '> <Param name = 'line0013' value = 'pie (-100,-100,200,200, "+ per123 +", "+ per4 +", 0) '> </Object>"

}
</SCRIPT>
</Head>
<Body>
<Table border = 1 width = 100%>
<Tr> <TD id = "chart" width = 50% Height = 400 align = center>
Prepare drawing... </TD>
<TD width = 50%>
<P align = center>
Enter 4 numbers <br>
<Input id = "value1" type = text size = 6 value = 0>
<Input id = "value2" type = text size = 6 value = 0>
<Input id = "value3" type = text size = 6 value = 0>
<Input id = "value4" type = text size = 6 value = 0>
</P>
<P align = center>
<Input type = button onclick = "drawpiechart ()" value = "Pie Chart">
</P>
</TD>
</Tr>
</Table>
</Body>
</Html>

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.