Velocity Reviews

Velocity Reviews (http://www.velocityreviews.com/forums/index.php)
-   Javascript (http://www.velocityreviews.com/forums/f68-javascript.html)
-   -   How to update a label using Javascript? (http://www.velocityreviews.com/forums/t934018-how-to-update-a-label-using-javascript.html)

gnewsgroup 12-23-2007 06:37 PM

How to update a label using Javascript?
 
In my asp.net 2.0 web application, I would like to display the process
progress information in the browser. The progress info is displayed
one after another with 1 or 2 seconds delay in between them. I
believe you guys have seen this a lot in a DOS console.

I have been trying this in my code-behind in C# for a few days with no
luck.

I think this must be achievable through javascript. But, I am new to
javascript, could you guys give me a hint on how to do this in
javascript? Thanks.

My Pet Programmer 12-23-2007 09:25 PM

Re: How to update a label using Javascript?
 
gnewsgroup said:
> In my asp.net 2.0 web application, I would like to display the process
> progress information in the browser. The progress info is displayed
> one after another with 1 or 2 seconds delay in between them. I
> believe you guys have seen this a lot in a DOS console.
>
> I have been trying this in my code-behind in C# for a few days with no
> luck.
>
> I think this must be achievable through javascript. But, I am new to
> javascript, could you guys give me a hint on how to do this in
> javascript? Thanks.


Where is the information displayed now? You could write the status
message to a file on each poll and pick it up via a simple tag in the
html, like:

<img id="dataImg" src="pageyouwroteto" style="visibility:hidden">, and
then use javascript to display it every second with:

<script type="text/javascript">
function updateStatus() {
document.getElementById("dataImg").src = "pageyouwroteto" +
new Date().getTimeMillis();
}
window.setInterval(updateStatus, 1000);
</script>

Randy might have a better way, from some of the stuff I've seen him post.

~A!

My Pet Programmer 12-23-2007 09:37 PM

Re: How to update a label using Javascript?
 
My Pet Programmer said:
> gnewsgroup said:
>> In my asp.net 2.0 web application, I would like to display the process
>> progress information in the browser. The progress info is displayed
>> one after another with 1 or 2 seconds delay in between them. I
>> believe you guys have seen this a lot in a DOS console.
>>
>> I have been trying this in my code-behind in C# for a few days with no
>> luck.
>>
>> I think this must be achievable through javascript. But, I am new to
>> javascript, could you guys give me a hint on how to do this in
>> javascript? Thanks.

>
> Where is the information displayed now? You could write the status
> message to a file on each poll and pick it up via a simple tag in the
> html, like:
>
> <img id="dataImg" src="pageyouwroteto" style="visibility:hidden">, and
> then use javascript to display it every second with:
>
> <script type="text/javascript">
> function updateStatus() {
> document.getElementById("dataImg").src = "pageyouwroteto" +
> new Date().getTimeMillis();
> }
> window.setInterval(updateStatus, 1000);
> </script>
>



I forgot to put in how you display it after you get it, I'm sorry about
that.

Here you might have a label on the page, and you could display the
status you got by modifying the function with:

document.getElementById('labelid').innerHTML =
document.getElementById("dataImg");

~A!

David Mark 12-23-2007 09:53 PM

Re: How to update a label using Javascript?
 
On Dec 23, 4:25*pm, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
> gnewsgroup said:
>
> > In my asp.net 2.0 web application, I would like to display the process
> > progress information in the browser. *The progress info is displayed
> > one after another with 1 or *2 seconds delay in between them. *I
> > believe you guys have seen this a lot in a DOS console.

>
> > I have been trying this in my code-behind in C# for a few days with no
> > luck.

>
> > I think this must be achievable through javascript. *But, I am new to
> > javascript, could you guys give me a hint on how to do this in
> > javascript? *Thanks.

>
> Where is the information displayed now? You could write the status
> message to a file on each poll and pick it up via a simple tag in the
> html, like:
>
> <img id="dataImg" src="pageyouwroteto" style="visibility:hidden">, and
> then use javascript to display it every second with:
>
> <script type="text/javascript">
> * *function updateStatus() {
> * * *document.getElementById("dataImg").src = "pageyouwroteto" +
> * * * *new Date().getTimeMillis();


Why getTimeMillis?

> * *}
> * *window.setInterval(updateStatus, 1000);


As written, there is no way to stop this interval.

> </script>
>


You are updating the src of a hidden image forever. What is the point
of that?

David Mark 12-23-2007 09:57 PM

Re: How to update a label using Javascript?
 
On Dec 23, 4:37*pm, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
> My Pet Programmer said:
>
>
>
>
>
> > gnewsgroup said:
> >> In my asp.net 2.0 web application, I would like to display the process
> >> progress information in the browser. *The progress info is displayed
> >> one after another with 1 or *2 seconds delay in between them. *I
> >> believe you guys have seen this a lot in a DOS console.

>
> >> I have been trying this in my code-behind in C# for a few days with no
> >> luck.

>
> >> I think this must be achievable through javascript. *But, I am new to
> >> javascript, could you guys give me a hint on how to do this in
> >> javascript? *Thanks.

>
> > Where is the information displayed now? You could write the status
> > message to a file on each poll and pick it up via a simple tag in the
> > html, like:

>
> > <img id="dataImg" src="pageyouwroteto" style="visibility:hidden">,and
> > then use javascript to display it every second with:

>
> > <script type="text/javascript">
> > * function updateStatus() {
> > * * document.getElementById("dataImg").src = "pageyouwroteto" +
> > * * * new Date().getTimeMillis();
> > * }
> > * window.setInterval(updateStatus, 1000);
> > </script>

>
> I forgot to put in how you display it after you get it, I'm sorry about
> that.
>
> Here you might have a label on the page, and you could display the
> status you got by modifying the function with:


More likely a div than a label. But a label is what the OP seems to
prefer.

>
> document.getElementById('labelid').innerHTML =
> document.getElementById("dataImg");


You are setting a string property to an element object. (?)

It seems your solution needs a little more work (and explanation.)

I am not sure what the OP wants, but this can't be it.

My Pet Programmer 12-23-2007 10:08 PM

Re: How to update a label using Javascript?
 
David Mark said:
> As written, there is no way to stop this interval.


You're right, I didn't put a stop in. He should only have it run during
the update and then stop. Excellent point, I should have paid better
attention to detail.

> Why getTimeMillis?


Is there a performance hit, or just a curiosity. It makes it clearer
what I'm doing in the code, I think. If it's inefficient, let me know
and I'll just comment better.

Ok, so an updated code listing then:

<script type="text/javascript">

function StatusUpdater(inID, outID) {
this.inElm = document.getElementById(inID);
this.outElm = document.getElementById(outID);
this._interval;

}

StatusUpdater.prototype.start =
function() {
this._interval = window.setInterval(this.update, 1000);
}

StatusUpdater.prototype.stop =
function() {
window.clearInterval(this._interval);
}

StatusUpdater.prototype.update =
function() {
if (inElm && inElm.src) {
if (outElm) {
outElm.innerHTML = inElm.src;
}
}
}

And the usage would be:

var updater = new StatusUpdater("myImageId", "myLabelId");
updater.start();
updater.stop();

And you'd call updater.start() when you started the remote procedure,
then updater.stop() when you finished.

Is that a little beter?

Thanks for the insight,
~A!

My Pet Programmer 12-23-2007 10:10 PM

Re: How to update a label using Javascript?
 
David Mark said:
> On Dec 23, 4:37 pm, My Pet Programmer <anth...@mypetprogrammer.com>
> wrote:
>> My Pet Programmer said:
>>
>>
>>
>>
>>
>>> gnewsgroup said:
>>>> In my asp.net 2.0 web application, I would like to display the process
>>>> progress information in the browser. The progress info is displayed
>>>> one after another with 1 or 2 seconds delay in between them. I
>>>> believe you guys have seen this a lot in a DOS console.
>>>> I have been trying this in my code-behind in C# for a few days with no
>>>> luck.
>>>> I think this must be achievable through javascript. But, I am new to
>>>> javascript, could you guys give me a hint on how to do this in
>>>> javascript? Thanks.
>>> Where is the information displayed now? You could write the status
>>> message to a file on each poll and pick it up via a simple tag in the
>>> html, like:
>>> <img id="dataImg" src="pageyouwroteto" style="visibility:hidden">, and
>>> then use javascript to display it every second with:
>>> <script type="text/javascript">
>>> function updateStatus() {
>>> document.getElementById("dataImg").src = "pageyouwroteto" +
>>> new Date().getTimeMillis();
>>> }
>>> window.setInterval(updateStatus, 1000);
>>> </script>

>> I forgot to put in how you display it after you get it, I'm sorry about
>> that.
>>
>> Here you might have a label on the page, and you could display the
>> status you got by modifying the function with:

>
> More likely a div than a label. But a label is what the OP seems to
> prefer.
>
>> document.getElementById('labelid').innerHTML =
>> document.getElementById("dataImg");

>
> You are setting a string property to an element object. (?)
>
> It seems your solution needs a little more work (and explanation.)
>
> I am not sure what the OP wants, but this can't be it.


So be it, then. Not what he wants, that's fine. You can set the property
to anything you like, though. It's definitely a hack, perhaps you could
give him a better solution?

~A!

gnewsgroup 12-23-2007 10:36 PM

Re: How to update a label using Javascript?
 
On Dec 23, 4:57 pm, David Mark <dmark.cins...@gmail.com> wrote:
> On Dec 23, 4:37 pm, My Pet Programmer <anth...@mypetprogrammer.com>
> wrote:
>
>
>
> > My Pet Programmer said:

>
> > > gnewsgroup said:
> > >> In my asp.net 2.0 web application, I would like to display the process
> > >> progress information in the browser. The progress info is displayed
> > >> one after another with 1 or 2 seconds delay in between them. I
> > >> believe you guys have seen this a lot in a DOS console.

>
> > >> I have been trying this in my code-behind in C# for a few days with no
> > >> luck.

>
> > >> I think this must be achievable through javascript. But, I am new to
> > >> javascript, could you guys give me a hint on how to do this in
> > >> javascript? Thanks.

>
> > > Where is the information displayed now? You could write the status
> > > message to a file on each poll and pick it up via a simple tag in the
> > > html, like:

>
> > > <img id="dataImg" src="pageyouwroteto" style="visibility:hidden">, and
> > > then use javascript to display it every second with:

>
> > > <script type="text/javascript">
> > > function updateStatus() {
> > > document.getElementById("dataImg").src = "pageyouwroteto" +
> > > new Date().getTimeMillis();
> > > }
> > > window.setInterval(updateStatus, 1000);
> > > </script>

>
> > I forgot to put in how you display it after you get it, I'm sorry about
> > that.

>
> > Here you might have a label on the page, and you could display the
> > status you got by modifying the function with:

>
> More likely a div than a label. But a label is what the OP seems to
> prefer.
>
>
>
> > document.getElementById('labelid').innerHTML =
> > document.getElementById("dataImg");

>
> You are setting a string property to an element object. (?)
>
> It seems your solution needs a little more work (and explanation.)
>
> I am not sure what the OP wants, but this can't be it.


OK, what I want is something like this (in C# instead of JavaScript,
to get my idea understood. BTW, we see such stuff all the time in
Thread programming tutorials.)

myLabel.Text = "Something to display...<br/>";
Thread.Sleep(1000);
myLabel.Text += "Something else to display...<br/>";
Thread.Sleep(1000);
myLabel.Text += "Some other stuff to show ... <br/>";

This will not work in an asp.net page. The page will be presented to
the browser after all of the output has been completed, and thus users
will see all 3 outputs above all at once.

It'll work if I do Response.Write in-line in the markup with
Response.Buffer = false. But, then it is hard to put these output in
a well-formatted page.

I hope that I have made myself understood.






David Mark 12-23-2007 10:46 PM

Re: How to update a label using Javascript?
 
On Dec 23, 5:08*pm, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
> David Mark said:
> *> As written, there is no way to stop this interval.
>
> You're right, I didn't put a stop in. He should only have it run during
> the update and then stop. Excellent point, I should have paid better
> attention to detail.
>
> *> Why getTimeMillis?
>
> Is there a performance hit, or just a curiosity. It makes it clearer
> what I'm doing in the code, I think. If it's inefficient, let me know
> and I'll just comment better.


What's wrong with getTime? I've never even heard of getTimeMillis.

>
> Ok, so an updated code listing then:
>
> <script type="text/javascript">
>
> function StatusUpdater(inID, outID) {
> * *this.inElm = document.getElementById(inID);
> * *this.outElm = document.getElementById(outID);
> * *this._interval;
>


That line doesn't do anything.

> }
>
> StatusUpdater.prototype.start =
> * *function() {
> * * *this._interval = window.setInterval(this.update, 1000);
> * *}
>
> StatusUpdater.prototype.stop =
> * *function() {
> * * window.clearInterval(this._interval);
> * *}
>
> StatusUpdater.prototype.update =
> * *function() {
> * * *if (inElm && inElm.src) {
> * * * *if (outElm) {
> * * * * *outElm.innerHTML = inElm.src;
> * * * *}
> * * *}
> * *}


You are confused. Did you try running this? Even if you straighten
out the errors, the best it will do is set the innerHTML of an element
to a URI.

>
> And the usage would be:
>
> var updater = new StatusUpdater("myImageId", "myLabelId");
> updater.start();
> updater.stop();
>
> And you'd call updater.start() when you started the remote procedure,
> then updater.stop() when you finished.
>
> Is that a little beter?


Not really.

David Mark 12-23-2007 10:48 PM

Re: How to update a label using Javascript?
 
On Dec 23, 5:10*pm, My Pet Programmer <anth...@mypetprogrammer.com>
wrote:
> David Mark said:
>
>
>
>
>
> > On Dec 23, 4:37 pm, My Pet Programmer <anth...@mypetprogrammer.com>
> > wrote:
> >> My Pet Programmer said:

>
> >>> gnewsgroup said:
> >>>> In my asp.net 2.0 web application, I would like to display the process
> >>>> progress information in the browser. *The progress info is displayed
> >>>> one after another with 1 or *2 seconds delay in between them. *I
> >>>> believe you guys have seen this a lot in a DOS console.
> >>>> I have been trying this in my code-behind in C# for a few days with no
> >>>> luck.
> >>>> I think this must be achievable through javascript. *But, I am new to
> >>>> javascript, could you guys give me a hint on how to do this in
> >>>> javascript? *Thanks.
> >>> Where is the information displayed now? You could write the status
> >>> message to a file on each poll and pick it up via a simple tag in the
> >>> html, like:
> >>> <img id="dataImg" src="pageyouwroteto" style="visibility:hidden">, and
> >>> then use javascript to display it every second with:
> >>> <script type="text/javascript">
> >>> * function updateStatus() {
> >>> * * document.getElementById("dataImg").src = "pageyouwroteto" +
> >>> * * * new Date().getTimeMillis();
> >>> * }
> >>> * window.setInterval(updateStatus, 1000);
> >>> </script>
> >> I forgot to put in how you display it after you get it, I'm sorry about
> >> that.

>
> >> Here you might have a label on the page, and you could display the
> >> status you got by modifying the function with:

>
> > More likely a div than a label. *But a label is what the OP seems to
> > prefer.

>
> >> document.getElementById('labelid').innerHTML =
> >> document.getElementById("dataImg");

>
> > You are setting a string property to an element object. (?)

>
> > It seems your solution needs a little more work (and explanation.)

>
> > I am not sure what the OP wants, but this can't be it.

>
> So be it, then. Not what he wants, that's fine. You can set the property
> to anything you like, though. It's definitely a hack, perhaps you could
> give him a better solution?


I don't understand your attempted solutions, nor do I fully comprehend
what the OP wants.


All times are GMT. The time now is 06:39 PM.

Powered by vBulletin®. Copyright ©2000 - 2014, vBulletin Solutions, Inc.
SEO by vBSEO ©2010, Crawlability, Inc.