Solved

displaying results of JavaScript in a div tag

Posted on 2011-09-15
11
339 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
Optimize your web performance

What's in the eBook?
- Full list of reasons for poor performance
- Ultimate measures to speed things up
- Primary web monitoring types
- KPIs you should be monitoring in order to increase your ROI

 
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 150 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 350 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

This article discusses how to implement server side field validation and display customized error messages to the client.
Originally, this post was published on Monitis Blog, you can check it here . In business circles, we sometimes hear that today is the “age of the customer.” And so it is. Thanks to the enormous advances over the past few years in consumer techno…
In this tutorial viewers will learn how to style a corner ribbon overlay for an image using CSS Create a new class by typing ".Ribbon":  Define the class' "display:" as "inline-block": Define its "position:" as "relative": Define its "overflow:" as …
The viewer will the learn the benefit of plain text editors and code an HTML5 based template for use in further tutorials.
Suggested Courses

623 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