/    Sign up×
Community /Pin to ProfileBookmark

Two (probably simple) questions

Hi,

Two quick questions:

1 I want to update the content of a div tag so I wrote the function:

[code]
function updateInnerHTML(theControl, theHTML) {
var newdiv = document.createElement(“div”);
newdiv.innerHTML = theHTML
var container = document.getElementById(theControl);
container.appendChild(newdiv);
//container.innerHTML(theHTML);
[/code]

The call to innerHTML didn’t work so I changed it to appendChild which is not the solution I want. Can anyone tell me why the innerHTML function wouldn’t work? I was passing in a short text string with no formatting.

2 I want to put my java functions in a seperate .js file and call them from my aspx file. I added the line:

[code]
<script type=”text/javascript” src=”JScript.js”>
[/code]

to the aspx file’s <head>. Is there anything else I need to do to call the functions in the js file?

Thanks to anyone who can help. I am totally new to javascript.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@FangJan 19.2010 — 
  • 1. Providing [I]theHTML[/I] is just text:var txtNode = document.createTextNode(theHTML);
    else use innerHTML after appending the element to the document.


  • 2. Depends on what the functions do.
  • Copy linkTweet thisAlerts:
    @rogerbaconauthorJan 19.2010 — 1. Providing [I]theHTML[/I] is just text:var txtNode = document.createTextNode(theHTML);
    else use innerHTML after appending the element to the document.
    [/QUOTE]


    Thanks. How can I do it without having a new node appended each time the function is called? I plan to call the function from a button and I don't want multiple text messages displayed.


    2. Depends on what the functions do.[/QUOTE]


    The function I posted above: updateInnerHTML.
    Copy linkTweet thisAlerts:
    @FangJan 19.2010 — 
  • 1. You're creating a new div each time so there will only be one node.


  • 2. Calling from the button will work.
  • ×

    Success!

    Help @rogerbacon spread the word by sharing this article on Twitter...

    Tweet This
    Sign in
    Forgot password?
    Sign in with TwitchSign in with GithubCreate Account
    about: ({
    version: 0.1.9 BETA 6.2,
    whats_new: community page,
    up_next: more Davinci•003 tasks,
    coming_soon: events calendar,
    social: @webDeveloperHQ
    });

    legal: ({
    terms: of use,
    privacy: policy
    });
    changelog: (
    version: 0.1.9,
    notes: added community page

    version: 0.1.8,
    notes: added Davinci•003

    version: 0.1.7,
    notes: upvote answers to bounties

    version: 0.1.6,
    notes: article editor refresh
    )...
    recent_tips: (
    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @meenaratha,
    tipped: article
    amount: 1000 SATS,

    tipper: @AriseFacilitySolutions09,
    tipped: article
    amount: 1000 SATS,
    )...