Pr.Pg Next Pg

HTML Interview Questions and Answers Part 4

 

31.How can I allow file uploads to my web site?

  • These things are necessary for Web-based uploads:
    An HTTP server that accepts uploads.

  • Access to the /cgi-bin/ to put the receiving script. Prewritten CGI file-upload scripts are available.

  • A form implemented something like this:

<form method="post" enctype="multipart/form-data" action="fup.cgi">
File to upload: <input type=file name=upfile><br>
Notes about the file: <input type=text name=note><br>
<input type=submit value=Press> to upload the file!
</form>

  • Not all browsers support form-based file upload, so try to give alternatives where possible The Perl CGI.pm module supports file upload.

  • The most recent versions of the cgi-lib.pl library also support file upload. Also, if you need to do file upload in conjunction with form-to-email, the Perl package MIME::Lite handles email attachments.

 

32.How can I require that fields be filled in, or filled in correctly?

  • Have the server-side (e.g., CGI) program that processes the form submission send an error message if the field is not filled in properly. Ideally, this error message should include a copy of the original form with the original (incomplete or incorrect) data filled in as the default values for the form fields.

  • The Perl CGI.pm module provides helpful mechanisms for returning partially completed forms to the user.
    In addition, you could use JavaScript in the form's ONSUBMIT attribute to check the form data.

  • If JavaScript support is enabled, then the ONSUBMIT event handler can inform the user of the problem and return false to prevent the form from being submitted.
    Note that the server-side program should not rely upon the checking done by the client-side script.

 

33.How do I change the title of a framed document?

  • The title displayed is the title of the frameset document rather than the titles of any of the pages within frames.

  • To change the title displayed, link to a new frameset document using TARGET="_top" (replacing the entire frameset).

 

34.How do I link an image to something?

  • Just use the image as the link content, like this:

<a href=...><img src=... alt=...></a>

 

35.How do I specify a specific combination of frames instead of the default document?

  • This is unfortunately not possible. When you navigate through a site using frames, the URL will not change as the documents in the individual frames change.

  • This means that there is no way to indicate the combination of documents that make up the current state of the frameset.
    The author can provide multiple frameset documents, one for each combination of frame content.

  • These frameset documents can be generated automatically, perhaps being created on the fly by a CGI program.

  • Rather than linking to individual content documents, the author can link to these separate frameset documents using TARGET="_top".

  • Thus, the URL of the current frameset document will always specify the combination of frames being displayed, which allows links, bookmarks, etc. to function normally.

 

36.How do I link to a location in the middle of an HTML document?

  • First, label the destination of the link. The old way to label the destination of the link was with an anchor using the NAME attribute. For example:
    <h2><a name="section2">Section 2: Beyond Introductions</a></h2>

  • The modern way to label the destination of the link is with an ID attribute. For example:
    <h2 id="section2">Section 2: Beyond Introductions</h2>

  • Second, link to the labeled destination. The URL is the URL of the document, with "#" and the value of the NAME or ID attribute appended. Continuing the above examples, elsewhere in the same document you could use:
    <a href="#section2">go to Section 2</a>

  • Similarly, in another document you could use:
    <a href="thesis.html#section2">go to Section 2 of my thesis</a>

 

37.How do I create a link?

  • Use an anchor element. The HREF attribute specifies the URL of the document that you want to link to. The following example links the text "Web Authoring FAQ" to

<URL:http://www.htmlhelp.com/faq/html/>:
<A HREF="http://www.yoursite.com/faq/html/">Web Authoring FAQ</A>

38.How do I create a link that opens a new window?

  • <a target="_blank" href=...> opens a new, unnamed window.
    <a target="example" href=...> opens a new window named "example", provided that a window or frame by that name does not already exist.

  • Note that the TARGET attribute is not part of HTML 4 Strict. In HTML 4 Strict, new windows can be created only with JavaScript. links that open new windows can be annoying to your readers if there is not a good reason for them.

 

39.How do I let people download a file from my page?

  • Once the file is uploaded to the server, you need only use an anchor reference tag to link to it. An example would be:
    <a href="../files/foo.zip">Download Foo Now! (100kb ZIP)</a>

40.How do I create a button which acts like a link?

  • This is best done with a small form:
    <FORM ACTION="[URL]" METHOD=GET>
    <INPUT TYPE=submit VALUE="Text on button">
    </FORM>

  • If you want to line up buttons next to each other, you will have to put them in a one-row table, with each button in a separate cell.

  • Note that search engines might not find the target document unless there is a normal link somewhere else on the page.

  • A go-to-other-page button can also be coded in JavaScript, but the above is standard HTML and works for more readers.

Pr.Pg Next Pg