Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

displaying results of JavaScript in a div tag

Posted on 2011-09-15
11
Medium Priority
?
342 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
  • 6
  • 4
11 Comments
 
LVL 83

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
Industry Leaders: 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 83

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 83

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 83

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

This article demonstrates how to create a simple responsive confirmation dialog with Ok and Cancel buttons using HTML, CSS, jQuery and Promises
A while back, I ran into a situation where I was trying to use the calculated columns feature in SharePoint 2013 to do some simple math using values in two lists. Between certain data types not being accessible, and also with trying to make a one to…
In this tutorial viewers will learn how to embed Flash content in a webpage using HTML5. Ensure your DOCTYPE declaration is set to HTML5: "<!DOCTYPE html>": Use the <object> tag to embed Flash content.: To specify that the object is Flash content, d…
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
Suggested Courses

926 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