Results 1 to 6 of 6

Thread: Inline Variables like ASP.net

  1. #1
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default Inline Variables like ASP.net

    Is it possible to reference a javascript variable as you would an asp.net variable.

    Code:
    var test="hello";
    HTML Code:
    <input type="textarea" value="<%=test%>">
    Ideally the value of the textarea should now be "hello" and it should update itself if the variable test is changed.

    I know it would be easier to assign the textarea a id and dynamically assign the value, but I have a situation where I am loading html code from a text file and putting it into a hta span using innerHTML. I need the loaded html code to populate itself with data using the inline variable method above.

  2. #2
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    ASP is processed on the server by a parser that "reads" through the entire page. Javascript, however, is only executed where there are script tags or events. So you will need to use an event.


    I wonder if placing this as the value would work....
    Code:
    value="<script type="text/Javascript">
    document.write(var);
    </script>"
    I don't think so, but maybe...

    Of course that would cause problems with the page if Javascript was disabled...
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  3. #3
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    What's:

    a hta span
    ?
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  4. #4
    Join Date
    Aug 2006
    Posts
    30
    Thanks
    1
    Thanked 0 Times in 0 Posts

    Default

    Quote Originally Posted by jscheuer1 View Post
    What's:



    ?
    The file which I'm trying to do this in is a .hta (Hyper Text Application). I'm trying to load HTML code from a .txt file into a <span></span>. The .txt file contains a template html code that must be able to populate itself using by referring to a javascript variable. I would assign id's to the html code but seeing it is a template it will be used many times and I can't have elements with the same id tag all over the place.

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    I see:

    http://www.fileinfo.com/extension/hta

    According to that, it's a Microsoft only thing. I suppose that if you were running asp.net server side on a Windows server, then it wouldn't matter. You could use PHP (also server side but more commonly available) to make your file an include. A similar syntax could then be used:

    PHP Code:
    <input type="textarea" value="<?php echo $test?>">
    AJAX may be used in conjunction with javascript to include a file without any special server side code being available. But the syntax would be radically different, and not as convenient.
    Last edited by jscheuer1; 09-09-2010 at 12:58 AM. Reason: strict syntax
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    PHP has a similar alternate "short tag" syntax for output. I don't like it, but it works (at least on most servers), and it's not actually deprecated, at least not yet (as of even PHP6).

    <?=$var?> which is the same as <?php echo $var; ?>
    Daniel - Freelance Web Design | <?php?> | <html>| espa˝ol | Deutsch | italiano | portuguŕs | catalÓ | un peu de franšais | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  7. The Following User Says Thank You to djr33 For This Useful Post:

    magicgavin (09-09-2010)

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
  •