Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations derfloh on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Variables in SVG? 1

Status
Not open for further replies.

snoopy75

Technical User
Joined
Aug 24, 2001
Messages
340
Location
US
We don't have an SVG forum, but this is the most closely related one, so I ask my question here:

I want to do something like this:
Code:
<?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
<!DOCTYPE svg PUBLIC &quot;-//W3C//DTD SVG 20000303 Stylable//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd&quot;>[/URL]
<svg xml:space=&quot;preserve&quot; width=&quot;350&quot; height=&quot;120&quot;>
Code:
var varD = 'M 50 10 L 350 10 L 200 120 z'
<path d=varD/>
Code:
</svg>
Is there a way to make an attribute dynamic like this? Thanks.

--Ryan
 
Code:
<?xml version=&quot;1.0&quot; encoding=&quot;iso-8859-1&quot;?>
<!DOCTYPE svg PUBLIC &quot;-//W3C//DTD SVG 20000303 Stylable//EN&quot; &quot;[URL unfurl="true"]http://www.w3.org/TR/2000/03/WD-SVG-20000303/DTD/svg-20000303-stylable.dtd&quot;>[/URL]
<svg xml:space=&quot;preserve&quot; width=&quot;350&quot; height=&quot;120&quot; onload=&quot;drawpath(evt)&quot;>
<script><![CDATA[
function drawpath(evt) {
  var varD = 'M 50 10 L 350 10 L 200 120 z';
  svgdoc=evt.getTarget().getOwnerDocument();
  var shape = svgdoc.createElement(&quot;path&quot;);
  shape.setAttribute(&quot;d&quot;, varD);
  output = svgdoc.getElementById(&quot;canvas&quot;);
  output.appendChild(shape);
}
]]></script>
<g id=&quot;canvas&quot;></g>
</svg>

Hope this helps.
 
Thanks! I found another way to do it using ASP, but I appreciate your answer... It will help me understand XML a little better! ;-)

--Ryan
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top