?
Solved

displaying results of JavaScript in a div tag

Posted on 2011-09-15
11
Medium Priority
?
341 Views
Last Modified: 2012-08-13
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
Comment
Question by:newbieweb
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 6
  • 4
11 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 36545001
var myresults = "RESULT HERE";
$("#you_div_or_span_ID").html( myresults );
0
 

Author Comment

by:newbieweb
ID: 36545040
No, I need a div tag that can display the returned valud from a function

function MyMessage() {
   return "Hello";
}

What's the HTML
0
 

Author Comment

by:newbieweb
ID: 36545047
<span> ??? </span>
0
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 82

Expert Comment

by:leakim971
ID: 36545074
$("#you_div_or_span_ID").html( MyMessage() );

http://jsfiddle.net/CCWFE/
0
 

Author Comment

by:newbieweb
ID: 36545164
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
 

Author Comment

by:newbieweb
ID: 36545174
It looks right, but where does your line of code go??

I am stuck.
0
 
LVL 2

Assisted Solution

by:Lord_Death
Lord_Death earned 600 total points
ID: 36545180
<!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
 
LVL 82

Accepted Solution

by:
leakim971 earned 1400 total points
ID: 36545215
<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
 

Author Comment

by:newbieweb
ID: 36546826
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
 
LVL 82

Expert Comment

by:leakim971
ID: 36546837
>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
 

Author Closing Comment

by:newbieweb
ID: 36546840
Thanks!
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

When it comes to write a Context Sensitive Help (an online help that is obtained from a specific point in state of software to provide help with that state) ,  first we need to make the file that contains all topics, which are given exclusive IDs. …
This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
In this Micro Tutorial viewers will learn how to create navigation buttons that change on rollover, using CSS (Continuation of the CSS Image Sprite tutorial) Create a parent ID for all the list items       - Specify position: absolute and display: block…
In this tutorial viewers will learn how to style elements, such a divs, with a "drop shadow" effect using the CSS box-shadow property Start with a normal styled element, such as a div.: In the element's style, type the box shadow property: "box-shad…

719 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question