Re: Talk with Javascript
by merlyn (Sage) on Sep 06, 2000 at 21:45 UTC
|
| [reply] |
Re: Talk with Javascript
by cwest (Friar) on Sep 06, 2000 at 21:02 UTC
|
I don't think you really want communication, but, if you did check out WDDX. I think you'll find it at http://www.wddx.org.
But for this case, I think WDDX could be over kill, try sending info back as javascript arrays.
Follow up on what you chose, especially if it was WDDX, I'm curious about how you might use it.
--
Casey
| [reply] [d/l] |
(crazyinsomniac) Re: Talk with Javascript
by crazyinsomniac (Prior) on Sep 06, 2000 at 21:44 UTC
|
<script language=javascript>
<!--//
var myaarray = new Array("item0","item1");
var myarray[0] = "f00f00f0";
function myClientSideSortFunction(foo)
{
//sortstuffnow
//output result of sort to form field
}
//-->
</script>
with the rest of your generated file
I suggest you use arrays, because forms can be changed by a user, unless you make them read only with javascript,
or hidden. Another reason to use arrays, it takes less characters than form fields, plus less code.
What kind of sort do you want to do?
for javascript help see http://www.webreference.com/js/
"cRaZy is co01, but sometimes cRaZy is cRaZy".
- crazyinsomniac | [reply] [d/l] |
|
|
Thanks for the help! But is it possible to do something like this:
print "Content-type: text/html\n\n";
print "<html><head><title>Matches</title>\n";
print "<SCRIPT src=../sort.js>\n";
print "</script></head>\n";
print "<body onload=init(this.form)>\n";
In other words, can CGI send back a HTML page that includes a javascript source file? I don't want to display the javascript functions and variables directly in the CGI program.
Thanks, Molly
| [reply] |
|
|
That's easy to do. Just open up your JavaScript source file, and do a nice tight loop like so:
open (INPUT, $filename) or warn "Can't open $filename: $!";
print while (<INPUT>);
close INPUT;
You'll have to put that after the headers and in the appropriate spot of your HTML, but it's not tricky.
I think you can also refer to an external JavaScript source file within the HTML, but maybe I'm confusing it with CSS. That's probably even easier. | [reply] [d/l] |
|
|
|
|
Somehow my sample code is not displayed correctly. Here is it again:
print "Content-type: text/html\n\n";
print "<html><head><title>Matches</title>\n";
print "<script src=../sort.js>";
print "</script></head>\n";
print "<body onload=init(this.form)>\n";
In other words, can CGI send back a HTML page that includes a javascript source file? I don't want to display the javascript functions and variables directly in the CGI program.
Thanks, Molly
| [reply] |
Re: Talk with Javascript
by jreades (Friar) on Sep 07, 2000 at 02:19 UTC
|
One issue not addressed yet is compatability -- do you need JavaScript 1.0 compatability or is 1.2 acceptible?
This is an important issue because it significantly affects what you're able to do on the client side -- 1.2 added primitive regexp support (O'Reilly JavaScript guide, starting page 165) as well as more sophisticated array handling (O'Reilly JavaScript guid page 153) which would make your life much, much easier.
Generally speaking, JavaScript 1.0 support corresponds to 3.x browsers (Netscape, IE) and 1.2 was available in the 4.x browsers. Things get trickier when you look at other browsers -- AOL is running IE's engine, but the versions are off so AOL 3 had something like IE 2-level support. Similar issues arise for Opera, iCab, and so on. The key point is, you need to know your audience in order to know what you have to play with.
If you need 1.0 compatability you're going to have to do much more work on the server side unless you want to get into some pretty heavy JavaScript coding (which can bring you to new levels of frustration).
Hope this helps.
| [reply] |
Re: Talk with Javascript
by Fastolfe (Vicar) on Sep 06, 2000 at 22:18 UTC
|
For some non-Javascript alternatives, you can try looking into XML and XSL in conjunction with Internet Explorer 5 or some ActiveX or Java applets. XML and XSL were made to do stuff like this. You would basically send your data in XML form to the browser/applet and use XSLT or equivalent to format the data how the user wants it to appear. This would include sorting. IE5 is capable of doing all of this natively, and this type of functionality is pretty simple to code, and, indeed, is generally "textbook" XSLT, so you shouldn't want for examples.
I don't know how much this helps you, since you seem to be wanting to do this in Perl somehow (or else you wouldn't be here), but I wanted to throw the alternative out there. | [reply] |
|
|
| [reply] |
|
|
| [reply] |