• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 345
  • Last Modified:

displaying results of JavaScript in a div tag

I need to display the returned string in HTML.

I have a JavaScript function which creates a string. Then I want to display it in an HTML span tag?

How?
0
newbieweb
Asked:
newbieweb
  • 6
  • 4
2 Solutions
 
leakim971PluritechnicianCommented:
var myresults = "RESULT HERE";
$("#you_div_or_span_ID").html( myresults );
0
 
newbiewebSr. Software EngineerAuthor Commented:
No, I need a div tag that can display the returned valud from a function

function MyMessage() {
   return "Hello";
}

What's the HTML
0
 
newbiewebSr. Software EngineerAuthor Commented:
<span> ??? </span>
0
Cloud Class® Course: C++ 11 Fundamentals

This course will introduce you to C++ 11 and teach you about syntax fundamentals.

 
leakim971PluritechnicianCommented:
$("#you_div_or_span_ID").html( MyMessage() );

http://jsfiddle.net/CCWFE/
0
 
newbiewebSr. Software EngineerAuthor Commented:
I do  not want a message box. I havee the box all taken care of. I want to display the returned valud from JavaScrip in HTML...


<span> returnStr() </span>

what's the format for calling returnStr() ??? It's a function.
0
 
newbiewebSr. Software EngineerAuthor Commented:
It looks right, but where does your line of code go??

I am stuck.
0
 
Lord_DeathCommented:
<!DOCTYPE HTML>
<html>
<script type="text/javascript">

    function MyScript()
    {
        var MyHTML = "<h3>This is a Sample</h3>";

        document.getElementById('MySpan').innerHTML = MyHTML;
        //Line Above Or Below no difference ;)
        MySpan.innerHTML = MyHTML;
    }  
</script>

<body onload="MyScript()">
    <span id="MySpan">
    </span>
</body>
</html>

Open in new window

0
 
leakim971PluritechnicianCommented:
<html>
<head>
script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
function MyMessage() {
   return "Hello";
}

window.onload = function() {
    $("#you_div_or_span_ID").html( MyMessage() );
}
</script>
<body>
<span id="you_div_or_span_ID"> ??? </span>
</body>
</html>

Open in new window

0
 
newbiewebSr. Software EngineerAuthor Commented:
leakim971, yours loks easiest to me. But, the creation of the return string is not known at load time. I'd like to call the function to initialize the function, when the dialog is being created.

It was suggested by a friend that in my jQuery function I initalize the span and "drill down" as needed.

It's got an ul and an li which I will set to have an empty value. Then I wil fill it from inside my function.

It's be great if youi had the code for that.


Thanks,
newbieweb
0
 
leakim971PluritechnicianCommented:
>But, the creation of the return string is not known at load time.

this is not a problem
line 10 we call a function, we don't know anything about the string until the function return it.

so all the job to be done is on this function : MyMessage

>when the dialog is being created.

so replace window.onload  by the name of the callback parameter of your dialog

not sure where we're going, I think you need to split your question
0
 
newbiewebSr. Software EngineerAuthor Commented:
Thanks!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Cloud Class® Course: Microsoft Office 2010

This course will introduce you to the interfaces and features of Microsoft Office 2010 Word, Excel, PowerPoint, Outlook, and Access. You will learn about the features that are shared between all products in the Office suite, as well as the new features that are product specific.

  • 6
  • 4
Tackle projects and never again get stuck behind a technical roadblock.
Join Now