1

This is the function

function seeHTML(elem){
var htmlTxt=document.getElementsByTagName('html')[0].innerHTML.toString();
elem.value=htmlTxt;
}

to call i use HTML

<input type="button" value="See HTML" onclick="seeHTML(txt)">

how to call it from another function as document.write

document.write(seeHTML(txt));

-- im a javascript begginer

however i tried document.write but it prints the function data itself, it doesnt use the function, how to ask it to use it then print the return (result)

1
  • Sorry, I didn't clearly get 1.) what do you want to print and 2.) where do you want to display it? Commented Apr 28, 2012 at 20:24

2 Answers 2

1
function foo(element) {
    seeHTML(element);
}

function seeHTML(element) {
}

foo(document.getElementsById('element'));
Sign up to request clarification or add additional context in comments.

Comments

0

in JavaScript code:

<script type="text/javascript">
document.addEventListener("DOMContentLoaded", call_your_function_here);
</script>

Here we created an event listener it means when the document is fully loaded the function() will be called, using the same way you can add any event listener to any DOM object, ex. you have a button with id="test", var btest = document.getElementById('test'); then

btest.addEventListener('click', function() { //execute code if btest object was clicked });

Bottom line you should call your function when the document is fully loaded hence replace the call_your_function_here() with your function name and if you wanted to reference the same button your function was embedded in use this syntax to reference the button DOM object:

var buttonObj = document.getElementById(buttonID);

then supply buttonObj to your function's argument.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.