|
How later?
Help people,so poeple can help you.
|
|
|
|
|
I am not sure exactly, but I think it will execute next chance it gets (i.e., after the current processing is complete). So, for example, if the page is still loading, the JavaScript will run after the page has loaded.
|
|
|
|
|
ok, sir;
i have used setTimeout() with 0 time to call client method when a message box dialog got closed. actualy i am not good in javascript, but i sow that call in some web resources used in ajax controls toolkit for asp.net.
plaese take a look at my article of Message Box Control[^] and tell me what do you think;
regards;
Help people,so poeple can help you.
|
|
|
|
|
Hi ,
I on button click I open a jquery modal with iframe which loads another aspx page.
Now this other aspx page makes a call to webservice and then loads data. I have the service call on the page load of this page.
So there a gap between the modal window opens and the data load in it.
How can I implement a wait gif or just a text like say 'processing' till the data loads?
Thanks
My code is as below
<div id="mydiv" >
<iframe id ="popup" width ="100%" height="50%"></iframe>
</div>
jquery/javascript
function openDialog() {
var url = "test.aspx?NAME=" + encodeURIComponent($("#<%=txtName.ClientID %>").val());
$("#popup").attr("src", url);
$("#mydiv").dialog('open');
}
$(document).ready(function() {
$("#mydiv").dialog({
autoOpen: false,
modal: true,
width: 500,
scroll: true
});
});
|
|
|
|
|
You don't really need to use an iframe in this instance, at least that I can see. iframes are typically used to display content from a different source, like a different URL. You can simply replace the the HTML content of the div. That would give you more control over the process
The general idea is
function openDialog()
{
$("#wait").show();
$.ajax({
url: "test.aspx?NAME=" + encodeURIComponent($("#<%=txtName.ClientID %>").val());,
success: complete;
}
});
}
function complete(result)
{
$("#wait").hide();
$("#mydiv").html(result);
}
I know the language. I've read a book. - _Madmatt
|
|
|
|
|
I have a problem and i can't figure out why th setTimeout function in this object doesn't tick...
Everything else work just fine but the no ticking. I've struggled with this almost all day but
i ca'nt get the setTimeout working...
Please u wiser ones, hjälp mej...auttakaa minua...help me...
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script type="text/javascript" src="js/prototype.js"></script>
<script type="application/javascript">
<!--
var objIdCnt = 0;
var objIdPre = "progressBar";
var ProgressBar = Class.create({
initialize: function(Container) {
this.Container = Container;
this.Id = objIdPre + objIdCnt++;
this.Type = 1;
this.Interval = 100;
this.Step = 2;
this.Stopped = true;
this.Min = 0;
this.Max = 100;
this.Position = 50;
this.Width = 100;
this.Left = 10;
this.Top = 10;
this.Visible = false;
this.t;
this.IncDecTotal = 0;
this.IncDec = 0;
this.ValTo = 0;
},
create : function(position, value)
{
if(this.Container == null)
{
alert("No container.");
}
else
{
var progBarImage;
progBarImage = document.createElement('IMG');
progBarImage.setAttribute("id", this.Id);
progBarImage.src = "img/Frame_200x16.png";
progBarImage.style.backgroundRepeat = "no-repeat";
this.Width = progBarImage.width;
progBarImage.style.backgroundPosition =
-(this.Width - (this.Position - this.Min) /(this.Max - this.Min) * this.Width) + "px 0px";
this.Container.appendChild(progBarImage);
this.Container.style.position = "absolute";
this.Container.style.left = this.Left + "px";
this.Container.style.top = this.Top + "px";
this.setType(value);
this.setPosition(position);
}
},
hide : function()
{
$(this.Id).style.visibility = "hidden";
},
show : function()
{
$(this.Id).style.visibility = "visible";
},
setPosition : function(position)
{
this.Position = position;
if(position > this.Max)
{
this.Position = this.Max;
clearTimeout(this.t);
}
if(position < this.Min)
{
this.Position = this.Min;
clearTimeout(this.t);
}
$(this.Id).style.backgroundPosition =
-(this.Width - (this.Position - this.Min) / (this.Max - this.Min) * this.Width) + "px 0px";
},
setType : function(value)
{
switch(value)
{
case 1: $(this.Id).style.backgroundImage = "url(img/RedBar_400x16.png)";
break;
case 2: $(this.Id).style.backgroundImage = "url(img/GreenBar_400x16.png)";
break;
case 3: $(this.Id).style.backgroundImage = "url(img/BlueBar_400x16.png)";
break;
}
},
doAnimate : function(value)
{
if(this.Position == value)
{
return;
}
this.IncDecTotal = 0;
this.ValTo = value;
this.IncDec = this.Step;
if(this.Position > value)
{
this.IncDec = -this.Step;
}
this.Stop = false;
this.timedAnimate();
},
timedAnimate : function()
{
this.setPosition(this.Position + this.IncDec);
if((this.IncDec < 0) && (this.Position <= this.ValTo))
{
clearTimeout(this.t);
this.Stop = true;
}
else if((this.IncDec > 0) && (this.Position >= this.ValTo))
{
clearTimeout(this.t);
this.Stop = true;
}
else
{
this.t = setTimeout("this.timedAnimate()", this.Interval);
}
},
sleep : function(delay)
{
var start = new Date().getTime();
var cur = start
while(cur - start < delay)
{
cur = new Date().getTime();
}
}
});
-->
</script>
</head>
<body>
<div id="progBar0"></div>
<br />
<input type="button" value="+5" onclick="progress0.setPosition(progress0.Position + 5);" />
<input type="button" value="-5" onclick="progress0.setPosition(progress0.Position - 5);" />
<div id="progBar1"></div>
<div id="progBar2"></div>
<script type="application/javascript">
<!--
var progress0 = new ProgressBar($("progBar0"));
var progress1 = new ProgressBar($("progBar1"));
var progress2 = new ProgressBar($("progBar2"));
progress0.create(25, 1);
progress1.Top = progress0.Top + 50;
progress1.create(50, 2);
progress2.Top = progress1.Top + 50;
progress2.create(75, 3);
progress1.doAnimate(100);
-->
</script>
</body>
</html>
</code>
If u want the images for testing, just ask...i'm glad to send them.
GBY:Olli.
Do u want to be always right or do u want to be happy...
|
|
|
|
|
Instead of this:
setTimeout("this.timedAnimate()", this.Interval);
Do this:
setTimeout(this.timedAnimate, this.Interval);
With your version, you are passing in a string, which gets evaluated when setTimeout runs your code rather than when you call setTimeout. So, "this" refers to a different scope/context. The solution is to pass in the actual function you want to be called.
|
|
|
|
|
I tried but it didn't worked...is the 'this' pointing window object rather than the object
i've created, if so do i have to move the timed animate to global or can i somehow other
way point it to window.setTimeout method?
I tried also use of closure attribute like setTimeout(function() { timedAnimate(); }, this.Interval),
but noo-ou-ou nothing happened.
i tried like this:
doAnimate : function(value)
{
if(this.Position == value)
{
return;
}
this.IncDecTotal = 0;
this.ValTo = value;
this.IncDec = this.Step;
if(this.Position > value)
{
this.IncDec = -this.Step;
}
alert("this: " + this + " this.IncDec: " + this.IncDec);
this.Stop = false;
this.timedAnimate();
},
timedAnimate : function()
{
this.setPosition(this.Position + this.IncDec);
if((this.IncDec < 0) && (this.Position <= this.ValTo))
{
clearTimeout(this.t);
this.Stop = true;
}
else if((this.IncDec > 0) && (this.Position >= this.ValTo))
{
clearTimeout(this.t);
this.Stop = true;
}
else
{
this.t = setTimeout(timedAnimate, this.Interval);
}
},
</code>
Olli.
|
|
|
|
|
Instead of this:
this.t = setTimeout(timedAnimate, this.Interval);
Try this:
this.t = setTimeout(this.timedAnimate, this.Interval);
|
|
|
|
|
I'll try that but meanwhile i moved the function to global scope and i pass the object to it. It works just fine but
it's not -in- the object so it ruins my OO way of thinking... (i'm mainly C++ programmer and JScript is new to me).
I made it like this:
function timedAnimate(elementId)
{
if(elementId.Stop == true)
{
return;
}
elementId.setPosition(elementId.Position + elementId.IncDec);
if((elementId.IncDec < 0) && (elementId.Position <= elementId.ValTo))
{
clearTimeout(elementId.t);
elementId.Stop = true;
}
else if((elementId.IncDec > 0) && (elementId.Position >= elementId.ValTo))
{
clearTimeout(elementId.t);
elementId.Stop = true;
}
else
{
elementId.t = setTimeout(function() { timedAnimate(elementId) }, elementId.Interval);
}
};
</code>
Olli.
|
|
|
|
|
Hi all,
I've kind of design where once an item is selected from a dropdownlist (HTML select) a new dropdown list is displayed with relevant items. It can be upto another level too. For example, say I've a dropdown to select the country. Once I choose the country relevant cities are displayed in another dropdown list below the original one. Once a city is selected from new list, hotels is displayed in that list.
Now say I submit the form and do the process. That part is fine. But once user click back button (to come back to that dorpdown lists page) I want to preserve user selections.
Any idea that how to do it.
All the lists generated with AJAX calls. Since dynamically generated list from the second level I cannot do with JS, using getElementByID() i cannot find them.
Comments really appreciate.
Thanks in advance
I appreciate your help all the time...
CodingLover
modified on Thursday, May 5, 2011 11:58 PM
|
|
|
|
|
Hi
May be this would be helpful.
1. before navigating from Dropdown page to another page you should save all the Three selected values (Country, City and Hotel in hidden field).
2. When you will get back then check is hidden field contain value.
3. Execute process one by one like
first get the Countries using AJAX call and set selected values according to Hidden field value.
and so on for the hotel...
The above is algorithm and i am not sure it is work or not but you may try something like that.
Thanks,
Imdadhusen
sunaSaRa Imdadhusen
+91 99095 44184
|
|
|
|
|
Thanks for the comment.
Actually what I've done was pass URL parameters with pre-define conding mechanism in my application. Your suggestion is worth to try, but I've already done it in that way. I'll give a try later on your suggestion.
Thanks again.
I appreciate your help all the time...
CodingLover
|
|
|
|
|
How status bar can be refreshed inside a loop? Is it even possible?
for(i = 0; i < items.length; i++ )
{
if(items[i]._category == category)
{
window.status = ('fillItemContent()' + ": " + i);
.
.
.
}
}
That doesn't work.
Olli.
|
|
|
|
|
status will probably not update as the message pump will not release until the loop stops and functions exit.
This is the same for windows forms etc.
I don't think you can force a refresh as you can with forms apps either.
One option might be to update a shared variable and then set up a timer that update the status based on the shared variable value and then the timer retriggers its next update timer tick. Use a flag to determine if the timer should continue to update or not.
|
|
|
|
|
I'm new with JScript, i'm C, C++ coder. Would u be kind enough to show me an little example. So, i make global variable or pass variable to setTimeOut method and update the status bar in there - or...what? The goal i want is to show load progression in status bar...and just practicing for fun...
Olli.
|
|
|
|
|
|
Id doesn't update the status bar in the loop...
var autoUpdate = true;
var autoUpdateString = "";
function updateStatusBar()
{
window.status = autoUpdateString;
autoUpdateString += ".";
}
function fillItemContent(category)
{
.
.
.
for(i = 0; i < items.length; i++ )
{
if(items[i]._category == category)
{
if(autoUpdate)
{
setTimeout(function() { updateStatusBar(); }, 10);
}
...
}
}
}
|
|
|
|
|
That is not how it should be. You need to drop the loop, just have a function that executes one iteration of it, and if it isn't the last iteration, use setTimeout to call itself again. That way the main (and only) thread gets relinquished for a short while, so the GUI can be updated and more calculations will happen later on.
Here[^] is an example.
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
Here is a working script (Note: Only tested in Chrome).
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>Status update test</title>
<script type="text/javascript">
var update = false;
var x = 0;
var theString = "";
function start() {
update = true;
setTimeout(function () { statusUpdate(); }, 10);
StartTimer.value = "Running.....";
}
function theInc() {
if (x < 10000000) {
x++;
theString = "Loop Value: " + x.toString();
}
else {
StartTimer.value = "Finished";
update = false;
}
}
function statusUpdate() {
TheValue.innerHTML = theString;
window.status = theString;
if (update) {
theInc();
setTimeout(function () { statusUpdate(); }, 10);
}
else {
TheValue.innerHTML = "Finished updating";
window.status = "Finished updating";
}
}
</script>
</head>
<body>
This is a test update page for the status updates within loop.
<input id="StartTimer" type="button" value="Start with Timer" onclick="start();" />
<div id="TheValue"></div>
</body>
</html>
|
|
|
|
|
Great example!
Luc Pattyn [Forum Guidelines] [My Articles] Nil Volentibus Arduum
Please use <PRE> tags for code snippets, they preserve indentation, improve readability, and make me actually look at the code.
|
|
|
|
|
|
You are still trying to use a loop.
You should perform an incremental increase on one item in each update then re-initiate the timer to call the update process for the next update, repeat until all items are updated.
|
|
|
|
|
|
'cause it won't work...sorry for bothering again...
var autoUpdate = false;
var theString = "";
function startUpdate()
{
autoUpdate = true;
setTimeout(function () { updateStatus(); }, 10);
window.status = "Start updating...";
}
function updateStatus()
{
window.status = theString;
if(autoUpdate)
{
setTimeout(function () { updateStatus(); }, 10);
}
else
{
window.status += " > Updated...";
}
}
function fillItemContent(category)
{
var frameTop = 20;
var frameLeft = 0;
var frameWidth = 0;
var frameHeight = 0;
var width = 256;
var height = 302;
var borderWidth = 2;
var horGap = 8;
var verGap = 8;
var colCount = 0;
var rowCount = 0;
var colCnt = -1;
var rowCnt = 0;
var art = 1;
var itemCount = 0;
var outerContent = document.getElementById('sisalto2');
for(i = 0; i &lt; items.length; i++)
{
if(items[i]._category == category)
{
++itemCount;
}
}
colCount = Math.floor(document.body.clientWidth / (width + horGap));
frameWidth = colCount * (width + 2 * borderWidth + horGap) + 2 + 2 * borderWidth;
frameLeft = (document.body.clientWidth - frameWidth) / 2;
rowCount = Math.ceil(itemCount / colCount);
frameHeight = rowCount * (height + 2 * borderWidth + verGap) + 2 + 2 * borderWidth;
theString = "";
startUpdate();
contentString = '&lt;div id="container_' + category + '" style="width: ' + frameWidth + 'px;'
+ ' height: ' + frameHeight + 'px; padding-top: 0; margin-top: 20px; margin-bottom: 38px; margin-left: '
+ frameLeft + 'px; border: solid thin #AAA;"&gt;';
for(i = 0; i &lt; items.length; i++ )
{
if(items[i]._category == category)
{
++colCnt;
theString += ".";
sleep(199);
contentString += (
' &lt;div id="art_' + i +'" style="position:absolute; border:thin solid #000;'
+ ' background-image: url(img/tuote_tausta.gif); width:' + width + 'px; height:'
+ height + 'px; margin:' + (rowCnt * (height + verGap + 2) + verGap) + 'px auto ' + 'auto '
+ (colCnt * (width + horGap + 2 * borderWidth) + horGap) + 'px;"&gt;'
+ ' &lt;div id="tuoteotsikko_' + i + '" style="text-align:center; color:#b5672d; height:18px; '
+ ' border-bottom:thin solid #000;'
+ ' padding:2px; background-color:#ff9b44;"&gt;&lt;strong&gt;'
+ items[i]._shortname + '&lt;/strong&gt;&lt;/div&gt;'
+ ' &lt;div id="tuote_kehys_' + i + '" style="border:;'
+ ' color:#000; text-align: center; background: none; width:128px; height:96px; '
+ ' margin:10px auto auto 10px;"&gt;'
+ ' &lt;img id="tuotekuva_' + i + '" height="96px" style="background-color: #666; cursor: pointer;'
+ ' moz-opacity:1;filter:alpha(opacity=100);"'
+ ' onmouseout="this.style.MozOpacity=1;this.filters.alpha.opacity=100"'
+ ' onmouseover="this.style.MozOpacity=0.5;this.filters.alpha.opacity=50"'
+ ' onclick="showModal(event)"'
+ ' src="' + itemImages[i].src + '" /&gt;&lt;/div&gt;'
+ ' &lt;div id="tuotetiedot_' + i + '" style="position:absolute; border:none; color:#000;'
+ ' text-align:right; padding:0;'
+ ' height:96px; width:96px; top: 18px; overflow: hidden;'
+ ' margin:13px auto auto 146px;"&gt;Hinta:&lt;br /&gt;&lt;strong&gt;' + items[i]._price + '&lt;/strong&gt;&lt;br /&gt;'
+ items[i]._desc2 + '&lt;/strong&gt;&lt;/div&gt;'
+ ' &lt;div id="tuotekuvaus_' + i + '" style="text-align:left; position:absolute; border:thin solid #AFAF61;'
+ ' color:#000; background-image: url(img/tuote_taustaRev.gif);'
+ ' text-indent: 0px; width:232px; height:148px; margin:10px auto 10px 10px;"&gt;' + items[i]._desc1 + '&lt;/div&gt;'
+ ' &lt;/div&gt;');
if(colCnt &gt;= (colCount - 1))
{
colCnt = -1;
++rowCnt;
}
}
}
contentString += '&lt;/div&gt;';
autoUpdate = false;
outerContent.innerHTML = contentString;
}
</code>
Olli.
|
|
|
|