Got this snippet of code, but getHTTPObject(); is not valid. What .js library need to get this working?
<script src="json2.js"></script>
var request;
function runAjax(JSONstring){
// function returns "AJAX" object, depending on web browser
// this is not native JS function!
request = getHTTPObject();
request.onreadystatechange = sendData;
request.open("GET", "parser.php?json="+JSONstring, true);
request.send(null);
}
// function is executed when var request state changes
function sendData(){
// if request object received response
if(request.readyState == 4)
// parser.php response
var JSONtext = request.responseText;
// convert received string to JavaScript object
var JSONobject = JSON.parse(JSONtext);
// notice how variables are used
var msg = "Number of errors: "+JSONobject.errorsNum+"
- "+JSONobject.error[0]+"
- "+JSONobject.error[1];
alert(msg);
}}
I have an online shopping cart and some of the products are sold in boxes of 6. So I am trying to write some code that will alert the customer if they have entered a quantity that isn't some multiple of six.
I've tried using the modulus operator as well as dividing by 6 and then checking to see if the result is a whole number but inevitably the alert box pops up no matter what I enter.
This is what I'm trying to use now:
Is there a better way to check if the entered quantity is a multiple of 6?
I am using jQuery 1.4.2 and I am trying to carry over the global variable totaltabs into my JSON callback function. The code seems to work properly, however, in my loadJSON function after the callback function loads the data, my totaltabs variable will not increment.
Here is a peak at my code.
totalItems is loaded from another function, not relevant to my example.
Code JavaScript: var totaltabs = 0; $(document).ready(function(){ resize();
I'm writing a function that substantially load a given image making a fadeout/faidin waiting 'till the complete load. The function is named "loadImage" and I would like use it in the following way: $('#image img').fadeOut().loadImage(src).attr("src",src).fadeIn();
In order to make the image disappear, load... change the attribute "src" of the image and then re-appear. The code for the function is: (function($) { $.fn.loadImage = function(src) { var img = new Image(); $(img).attr('src', src).load(function() { return this; }); }})(jQuery);
But when I run it I get the following error: $("#image img").fadeOut().loadImage(src) is undefined I think that the function don't return a "valid" object to make it chainable, isn't it?
I am making a small gallery script. When a user clicks an image, I would like for a function to be called that tells the browser where that image is located in an object. For example:
[Code]...
It works, I just don't like it because it is messy and it seems sensible that some workaround exists.
I have the following funciton that centers my website content for any size window and will center it in real time as the window is expanded or shrunk. It is activated by a
onresize="CenterIt();"
in the body tag.
Works fine for IE. How do I make it compatible with netscape and most browsers? Better yet, is there a good single source that explains how to write javascript to be compatible with all browsers? 766 and 435 are the width and height of my table that surrounds the website data defined so:
This is one example .... this is repeated about 20 times in the program, one for each year of our history...
It works fine ... but not on all the browsers in our office. Most work fine ... others (all IE) work fine on some dates; other dates, when you hover, flash a blank page repeatedly until you move the mouse away; almost as though it is looping ...
I notice that "about:blank" flashes briefly before the called page comes up ... but that appears to be normal.... I have checked and rechecked all coding, all brackets and semi-colons ... and it works perfectly -- for me and for a few others.
I have a idea to remove the cookie value from a website after all browser closed. It is like session kept in server and eliminate after all browser closed. My purpose is reducing browsing security issue through minimize the data resident in the cookie. The reason i using the cookie instead of session because I used cookie in applying SSO (Single Sign On) for different web application server instead of single server. I know we able detect a browser closed via onunload javascript, but i need to detect when i closed all browser.
Suppose there is a function myFunction() defined in a web page. Now how can a visitor call this function manually, using the JS console or Firebug etc.Is this possible?
The following code works for Firefox but not on Chrome. Does anybody know what it doesn't work on Chrome. Is there a document on the browser compatibility info on each JQuery command.
I need to call a javascript function when the user closes the browser window. I have tried onunload but that runs when the user clicks a new link as well. I need something that only runs when the browser window is closed.
I want to know is it possible if I want to create a JavaScript function that when user choose menu to print a web page from the browser (not from a print button that is created) and at the same time get that print date and update to the database using PHP? And if it is possible, how to create that function?
I've been doing a bit of research and haven't found anything too easy. Can anyone point me to an article that has a function written in javascript that validates that a date that has been submitted via a form that it is a valid date?
I am building a custom validator. I don't want any suggestions on using a jQuery framework, i just want to ask a few question on how best to continue.
Code: <script type="text/javascript"> //Validator Strings And Expressions. var Letters = /^[A-Za-z]+$/;
[Code].....
This is the "on page" validation. This, as you can see calls functions held in an included file onkeyup. This all works well, also the username check ajax call works great. However I have 2 questions that I need to sort before this will work correctly.
1. Using M_USERNAME form as an example. If I start typing in there it will begin validating, which is great, However, if i typed in "matt_thomas" based on the validations, Empty:Pass, ValidChars:Fail, Range:Pass, Check:Pass.
So I know that it isn't empty, it's the correct length and it's not already in the DB. But it fails because of the "_". This should mean that I receive the error i have setup for that failure. But I don't. Because I don't stop on a Fail, I receive the success message of the last function.
So my question is; How Can I stop running any more functions when one fails?
2. Looking at the above code, How can I make sure that a submit will only work when ALL fields validate correctly?
The following script generates three SELECT menu's... one for days one for months and one for years. Each time a new year or a month is selected the menu's are updated to allow only valid dates. Its only just been finished and could probably use commenting more, but im always open to suggestions, advice and criticism.