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 IamaSherpa on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Cgi/javascript interface

Status
Not open for further replies.

marsd

IS-IT--Management
Apr 25, 2001
2,218
US
I'm trying to build a small tcl/javascript library for
my own, personal, use using cgi.tcl.

I have several issues with passing tcl variables to a
javascript function.
I'm stuck on how to deal with some substitution issues.

A sample problem:
proc areaCreate {mn an clist href handler} {
js::tclcodeinsert function areaCreate() {
document.write(&quot;<map name=$mn>&quot;);
document.write(&quot;<area name=$an&quot;);
document.write(&quot;coords=$clist&quot;);
document.write(&quot;href=$href&quot;);
document.write(&quot;target=_top&quot;);
document.write(&quot;onDblClick=$handler>&quot;);
}
return 2
}


proc tclcodeinsert {args} {
foreach line [split $args \n] {
if {[regexp &quot;.*=(.*)\&quot;.*&quot; $line all val]} {
uplevel #1 &quot;catch {puts $all}&quot;
} else {
catch {cgi_buffer [puts $line]}
}
}
return
}

The output from something like this:
js::initjs ; js::areaCreate bogus bogus1 &quot;1,1,34,56&quot; &quot; &quot;myhandler()&quot; ; js::closejs

Looks like this:
<script>

function areaCreate() {
document.write(&quot;coords=1,1,34,56&quot;)
document.write(&quot;href=document.write(&quot;target=_top&quot;)
document.write(&quot;onDblClick=myhandler()>&quot;)
}

</script>

You'll notice the problem..
I can get all lines without variable substitution
or some lines with variable substitution but not
both together.
Does anybody see an easier way to do this than
reading the args twice, storing non-regexp matches
in order, then regexp matches in order and rewriting
the output via custom parray?
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top