Hello,
My landing page contains a big google maps portion, which slows down the loading time. I am trying to do the following:
Load the static elements first so the page loads fast initially.
Display a loading notification in the map placeholder so that the user knows that the map is coming up
Load and display the map
I have done this:
$(document).ready(function() {
map_initialize();
}
map_initialize() being the function which loads the map into its container div. However, this still will not display the static elements fist. The page will wait until the map_initialize() is finished, then load the static elements at the same time as the map.
Thanks,
For the love of God I am not getting this easy code to work! It is always alerting out "null" which means that the string does not match the expression.
var pattern = "^\w+@[a-zA-Z_]+?\.[a-zA-Z]{2,3}$";
function isEmailAddress(str) {
str = "[email protected]";
alert(str.match(pattern));
return str.match(pattern);
}
I have a tree view which has a folder icon by default and once clicked it has to be changed to a checkbox icon. And further on clicking the checkbox icon should display a folder icon.
Sample Code,
Server side : c#
htmlSb.AppendFormat(" {0}", emptyContent);
JS code
var Test= new Object();
Test.Controls=new Object();
Test.Controls.TreeView = new Object();
**Test.Controls.TreeView.SelectNode = function (TreeId, nodeLabel) {
$("#" + TreeId + " li span, ul li span").css("background-color", "transparent");
nodeLabel.style.backgroundColor = "white";
nodeLabel.style.background = "url(../images/selected.gif) 0 0 no-repeat";
}**
The other Image :
if (nodeLabel.style.background = "url(../images/folderclosed.gif) 0 0 no-repeat")
I need to toggle between "selected.gif" and "folderclosed.gif" images. If one is clicked the other should display. and vice versa.
Please help.
Is it considered a bad practice to pass around a large string or object (lets say from an ajax response) between functions? Would it be beneficial in any way save the response in a variable and keep reusing that variable?
So in the code it would be something like this:
var response;
$.post(url, function(resp){
response = resp;
})
function doSomething() {
// do something with the response here
}
vs
$.post(url, function(resp){
doSomething(resp);
})
function doSomething(resp) {
// do something with the resp here
}
Assume resp is a large object or string and it can be passed around between multiple functions.
I have the following code.
var d3_ad = 1;
function displayD3Ad(){
var query_string = '?d3_ad='+d3_ad;
query_string += '&location='+escape(location);
//document.write('<iframe src="index.php'+query_string+'"></iframe>');
var data = httpRequest('http://localhost/test/index.php','GET',query_string);
document.write(data);
}
function httpRequest(strURL,type,query) {
var request = false;
if (window.XMLHttpRequest) {// Mozilla/Safari
request = new XMLHttpRequest();
} else if (window.ActiveXObject) { //Internet Explorer
request= new ActiveXObject("Microsoft.XMLHTTP");
}
request.open(type, strURL + query, true);
request.setRequestHeader('Content-Type', 'application/x-www-form-urlencoded');
request.onreadystatechange = function() {
if (request.readyState == 4) {
return request.responseText;
}
}
request.send(null);
}
displayD3Ad();
now when it writes out the data it is saying undefined. It seems like it isnt returning the data. I looked in firebug and it completes and shows the response that shoudl be there. Any help is appreciated. I just need to set the data variable so that I can use it later on.
How do I write a swtich for the following conditional?
If the url contains "foo", then settings.base_url is "bar".
The following is achieving the effect required but I've a feeling this would be more manageable in a switch:
var doc_location = document.location.href;
var url_strip = new RegExp("http:\/\/.*\/");
var base_url = url_strip.exec(doc_location)
var base_url_string = base_url[0];
//BASE URL CASES
// LOCAL
if (base_url_string.indexOf('xxx.local') > -1) {
settings = {
"base_url" : "http://xxx.local/"
};
}
// DEV
if (base_url_string.indexOf('xxx.dev.yyy.com') > -1) {
settings = {
"base_url" : "http://xxx.dev.yyy.com/xxx/"
};
}
Thanks
Hello everyone.
In Firebug the DOM tab shows a list of all your public variables and objects. In Chrome's console you have to type the name of the public variable or object you want to explore. Is there a way - or at least a command - for Chrome's console to display a list all the public variables and objects? It will save a lot of typing.
Thank you all
Stefanos
Hi,
I want to do something like this: user selects one radio button (lock,delete or compare).
I want to show to him only the relevant column from the table. (each option has different column). The table is ajax.
I guess i need to change the display style for every cell but i don't know how.
Here is example:
Here i want to change the display of the cells
function ButtonForTbl(value) {
var x=document.getElementById("audithead").rows[0].cells;
if (value == "lock"){
document.getElementById('lock').checked = true;
//something like for(...)lockCell.style.display=''
//something like for(...)deleteCell.style.display='none'
//something like for(...)compareCell.style.display='none'
}
else if(value == "delete"){
document.getElementById('delete').checked = true;
//something like for(...)lockCell.style.display='none'
//something like for(...)deleteCell.style.display=''
//something like for(...)compareCell.style.display='none'
}
else{
document.getElementById('compare').checked = true;
}
}
I guess i need something like that:
for (i = 0; i < deleteCell.length; i++)
deleteCell[i].style.display='' = true ;
The table:
oCell = oRow.insertCell(-1);
oCell.setAttribute('id','comCell' );
oCell.setAttribute('align', 'center');
oCell.innerHTML = "<input type='checkbox' id='com' value='"+ ind + "'name='com[]'>";
oCell = oRow.insertCell(-1);
oCell.setAttribute('id','lockCell' );
oCell.setAttribute('align', 'center');
oCell.innerHTML = "<input type='checkbox' id='lock' value='"+ ind + "'name='lock[]'>";
Radio buttons:
<input type="radio" value="compare" id="compare" name="choose" onclick="ButtonForTbl(this.value)"/> Compare
<input type="radio" value="delete" id="delete" name="choose" onclick="ButtonForTbl(this.value)"/> Delete
<input type="radio" value="lock" id="lock" name="choose" onclick="ButtonForTbl(this.value)"/> Lock<br/>
The table html:
<table class="auditable">
<thead id="audithead">
<tr><td></td></tr>
</thead>
<tbody id="auditTblBody">
</tbody>
</table>
EDIT:
Full row is like that:
<tr>
<td align="center" id="lockCell" style="display: none;">
<input type="checkbox" onclick="" name="lock[]" value="1500" id="lock"></td>
<td align="center" id="delCell" style="display: none;">
<input type="checkbox" name="del[]" value="1500"></td>
<td align="center" id="comCell">
<input type="checkbox" onclick="setChecks(this)" name="com[]" value="1500" id="com"></td>
<td width="65px">100% 1/1</td><td width="105px">2011-01-10 17:47:37</td>
</tr>
Thank you so much!
I am toying with an application that will demo some Firefox 3.6 specific functionality, most of which are listed here: http://demos.hacks.mozilla.org/openweb/
I want to drag a zip file in the browser, unzip it, and work with the unzipped contents.
Are there any existing libraries that can do this? Does FireFox 3.6 in particular have something I can use? Or would I have to roll my own unzipper library?
For the record: http://github.com/augustl/js-unzip
Hi, I am using syntaxhighlighter (http://alexgorbatchev.com/wiki/SyntaxHighlighter) with a php source code with the ins and del tag.
What I would like to do is to have syntaxhighligher ignore those html tags so that they can be parsed correctly. So I'd like to to display:
test
instead of the default
< del test < /del
Anyone has any idea?
Flip is a great JQuery plugin for flipping blocks, but it doesn't preserve the background while it animates the flip.
For example, I have this pretty background, here, before I flip. While flipping, it gets ugly: here.
Is there a way I can flip this div nicely, keeping the pretty background I have, and maybe even achieve a smoother animation than I can get with Flip?
If I need to dive into this headfirst and code my own function for flipping a div, that's also doable, and I'd really appreciate some pointer there, if that's what I must do.
Thanks so much!
Hi all, I am working on a class assignment in which i need to accomplish the following:
1 User types a list of items into a text box (form field)
2 When the user presses the sort button, the list in the text box is sorted
3 It takes the text from the text box and puts the sorted text back in the text box
Please help!
I am looking at redesigning my website and was wondering if I could get some opinions.
I know that the rule is usually to design with users without JS first and foremost, but having looked at the stats, it appears 95% of the users online have JS enabled.
Would you recommend designing the website using JS and not bothering about people without it?
How to create regex pattern which is concatenate with variable, something like this:
var test ="52";
var re = new RegExp("/\b"+test+"\b/");
alert('51,52,53'.match(re));
Thanks
After doing some reading about the Module Pattern, I've seen a few ways of returning the properties which you want to be public.
One of the most common ways is to declare your public properties and methods right inside of the "return" statement, apart from your private properties and methods. A similar way (the "Revealing" pattern) is to provide simply references to the properties and methods which you want to be public. Lastly, a third technique I saw was to create a new object inside your module function, to which you assign your new properties before returning said object. This was an interesting idea, but requires the creation of a new object.
So I was thinking, why not just use "this.propertyName" to assign your public properties and methods, and finally use "return this" at the end? This way seems much simpler to me, as you can create private properties and methods with the usual "var" or "function" syntax, or use the "this.propertyName" syntax to declare your public methods.
Here's the method I'm suggesting:
(function() {
var privateMethod = function () {
alert('This is a private method.');
}
this.publicMethod = function () {
alert('This is a public method.');
}
return this;
})();
Are there any pros/cons to using the method above? What about the others?
function getWindowsUserName()
{
var WinNetwork = new ActiveXObject("WScript.Network");
var urlToSite = "http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS=" & WinNetwork.username
document.getElementById(psyncLink).value = urlToSite;
}
I am trying to make the frame load the urlToSite
<frameset cols="300px, *">
<frame src="topo1.htm" name="topo" id="topo" application="yes" />
<frame src="http://localhost/index.php?nph-psf=0&HOSTID=AD&ALIAS=" name="psync" id="psyncLink" application="yes" />
</frameset>
I have to be missing something simple, but I'm really not sure what. I'm not a JS veteran, so this may be an easy answer - sure hope so :).
I have a button that, when clicked, gets JSON data. When a drop-down is changed, I check to see if there is data, if there is, I want to clear it out as the drop-down indicates what data to retrieve when the button is clicked
The Code:
var selected, $locDialog;
var locations = [];
$(function() {
// Save the selected Name
selected = $("#selected option:selected").val();
// Setup Dialog for Locations
$locDialog = $('#location-dialog').dialog({
autoOpen: false
});
// If user changes the selected
// 1. Prompt for confirmation
// 2. If users confirms, clear data
$('#selected').change(function() {
if (locations) {
var confirmed = confirm("Oh Rly?");
if (confirmed) {
// Clear data
var locations;
}
}
});
// When user clicks "Location" Button..
$('.loc-select button').click(function() {
if (!locations) {
$.getJSON("/Controller/JSONAction", { selectedId: selected, pageNum: 1, pageSize: 100 }, function(data) {
locations = data;
$.each(locations, function(index, loc) {
var $tr = $('<tr/>')
.append($('<td/>')
.append('<input type="checkbox" name="TEST-'+index+'" value="'+loc.Id+'"/>'))
.append('<td>' + loc.Name + '</td>');
$("#location-dialog table tbody").append($tr);
});
});
}
$locDialog.dialog('open');
return false;
});
});
Here's the thing, Inside the .click(...) callback, I can see locations is []. Now, when I am in the .change(...) callback, I see locations is undefined.
Any help/insight, as always, is appreciated!
I have a three strings of categories
"SharePoint,Azure,IT";
"BizTalk,Finance";
"SharePoint,Finance";
I need to find a way to check if a string contains for example "SharePoint" and "IT", or "BizTalk" and "Finance". The tests are individual strings themselces.
How would i loop through all the category strings (1 - 3) and only return the ones which have ALL instances of the souce.
i have tried the following
function doesExist(source, filterArray)
{
var substr = filterArray.split(" ");
jQuery.each(substr, function() {
var filterTest = this;
if(source.indexOf(filterTest) != -1 )
{
alert("true");
return true;
}else
{
alert("false");
return false;
}
});
}
with little success...the code above checks one at a time rather than both so the results returned are incorrect. Any help would be great.
Thanks
Chris
UPDATE: here is a link to a work in progress version..http://www.invisiblewebdesign.co.uk/temp/filter/#
I have a Scripts folder, that includes all the .js files used in the project. Using the Ajax Minifier task, I generate .min.js files for each one.
Depending on whether the application is running in debug or release mode, I include the original .js file, or the minified one.
The Scripts folder looks like this:
Scripts/script1.js
Scripts/script1.min.js // Outside the project, generated automatically on build
Scripts/script2.js
Scripts/script2.min.js // Outside the project, generated automatically on build
The .min.js files are outside the project (although in the same folder as the original files), and they are not copied into the destination folder when we publish the project.
I have no experience whatsoever using build tasks (well, apart from including the minifier task), so I would appreciate if anyone could advise me as to which would be the correct way to:
Copy the .min.js files to the destination folder when I publish the app from Visual Studio.
Delete / Not copy the original js files (this is not vital, but I'd rather not copy files that will not be used in the app).
Thanks,
Hi All
I am available with the solution given by @Tomalak for MY QUESTION could you pls help me out with it as its giving me an error in firebug as : frm.creatorusers is undefined
[Break On This Error] var rdo = (frm.creatorusers.length ...rm.creatorusers : frm.creatorusers;
I used the code for validating radio button as:
function valDistribution(frm) {
var mycreator = -1;
var rdo = (frm.creatorusers.length > 0) ? frm.creatorusers : frm.creatorusers;
for (var i=0; i<rdo.length; i++) {
if (rdo[i].checked) {
mycreator = 1;
//return true;
}
}
if(mycreator == -1){
alert("You must select a Creator User!");
return false;
}
}
How do I skip over this next line if it turns out to be null? Currently, it (sometimes) "breaks" and prevents the script from continuing.
var title = (/(.*?)<\/title/m).exec(response)[1];
$.get(url, function(response){
var title = (/<title>(.*?)<\/title>/m).exec(response)[1];
if (title == null || title == undefined){
return false;
}
var words = title.split(' ');
$.each(words, function(index, value){
$link.highlight(value + " ");
$link.highlight(" " + value);
});
});
I have an HTML table that should be updated according the file that user uploads.
In other words, I would like user to be able to upload a file, and change the contents of the table according to file content.
The file size can be several MB.
What are my options ?
Do I must to upload the file to a server, or it can be done in client side ? Thanks !