SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Enthusiast buffyspazz's Avatar
    Join Date
    Jan 2002
    Location
    Richmond, VA
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    XHTML and scripts

    Since XHTML won't work with a lot of scripts (if they have a "<", etc. tag in them), I need some help. I'm using a free cgi script for a form (which works great), but I'm wondering if you can "call" a cgi script like you can a javascript - the script configuration section in my html has a lot of "<" in it, and since the CDATA element isn't supported in any browsers yet (well, IE and Netscape, anyway, not sure about the rest), I don't know how to use this script if I were to try and change the page to be XHTML. Any ideas?

  2. #2
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    CGI is handled on the server, not the client, so it shouldn't be a problem. Only the output really matters. All the CGI bits are removed and replaced by whatever they do, correct?

    BTW, what language are you using?

    ~~Hope This Helps

  3. #3
    SitePoint Enthusiast buffyspazz's Avatar
    Join Date
    Jan 2002
    Location
    Richmond, VA
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Well...

    Here's where I reveal my true ignorance. I've got a link to one of the pages in question so you can see the script in context, plus it's below.

    Let me say that I know that this page is not XHTML compliant right now...I'd need to get rid of the font tags, etc. etc. etc., but I'm just thinking in terms of the future, trying to convince the people at my work that it's worth it to work toward compliance, even if it means using CSS more extensively and having less than beautiful pages in older browsers. However, I'm worried about the three or four pages we have with forms.

    I know how to code my site to get rid of all of the deprecated tags, but on the pages with forms, since the CGI script has some "<", etc. tags, it would be invalid XHTML, according to this info from the XHTML Guru website:

    One of the changes of XHTML which will make transitioning from HTML based browsers to XHTML based browsers difficult is the handling of <SCRIPT> elements. Under HTML 4, the following is valid:

    <script>
    var counter = 0;
    function test() {
    if (counter < 5) {
    counter++;
    } else {
    alter("Call Doug & Margaret for " +
    "permission to go above 5!")
    }
    }
    </script>

    Unfortunately, the above code would be invalid under XHTML. Why? Under XML, the script code would actually be parsed for HTML tags. The less-than sign, <, in the line if (counter < 5) would be interpreted as the beginning of a tag. and an XHTML parser would get confused. It only requires a slight modification to fix.


    <script type="text/javascript">
    <![CDATA[
    var counter = 0;
    function test() {
    if (counter < 5) {
    counter++;
    } else {
    alter("Call Doug & Margaret for " +
    "permission to go above 5!")
    }
    }
    ]]>
    </script>

    Encapsulating the script in a CDATA element would inform a XML parser not to check the contents for tags. You do this by starting the script with <![CDATA[ and ending it with ]]> . Unfortunately, the above code doesn't work in current HTML browsers like IE and Netscape. So for now, the only solution would be to save the JavaScript to an external file, like so:
    <script language="Javascript"
    type="text/javascript" src="script.js">
    </script>

    Where the file script.js contains:
    var counter = 0;
    function test() {
    if (counter < 5) {
    counter++;
    } else {
    alter("Call Doug & Margaret for " +
    "permission to go above 5!")
    }
    }

    Here's the script I'm using (from BigNoseBird.com. My understanding of CGI is shaky at best - I know how to put the script (that someone else wrote, of course!) into my html and how to ftp the script into the proper directories - in other words, I can make the form work, but I really don't know anything else about CGI. As for what language I'm using, I assume you're not talking about HTML, so that would leave the CGI script, and I'm not sure...I mean, I know it's written in perl, and that's what I'm guessing you're asking, but I could be wrong (about what you're asking)...I'm wrong about so many other things.

    Anyway, here's the link to the page: http://www.fpcgvl.org/about_us/contact_us.html. If you or anyone else can tell me how CGI scripts will work in XHTML I will very happy and appreciative.

  4. #4
    SitePoint Wizard Ian Glass's Avatar
    Join Date
    Oct 2001
    Location
    Beyond yonder
    Posts
    2,384
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You don't have to worry about a thing, I think. If you take a gander at the source, you'll notice that the CGI portions have all been processed and removed on the server, before you ever get that page. That's not going to present a barrier for compliancy with the standards. :-)

    In the future if you ever come across a JavaScript with the greater-than symbol, you just use an external reference to that script for the most part. You should have no problems with that as far as XHTML is concerned.

    ~~Ian


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •