JQuery :: Width Function Returning Zero On Occasion?

May 26, 2010

I have a weird bug that's occuring in pretty much all the browsers. If I close the tab, and then hit Ctrl -> Shift -> T to bring it back the width() method returns 0 on an appended image instead of what the image actually is. Hitting refresh on the tab removes this bug and everything works fine. I will also say that trying
.css('width') and
document.getElementById('divShadowLeft');
Both also return 0 for this bug.

I can't show all the code for security reasons, but I'll just outright ask.. what are the reasons that width() would return 0 on an image? I've checked to make sure that it was visible (both display and visibility properties), and I checked the length of the property to ensure it was there. I just can't figure out why width() is returning 0.

Here's a code snippet:
$(this).append('<img src="'+defaults["imagePath"]+defaults["imageLeft"]+'" alt="" id="'+defaults["imageClass"]+'Left" class="'+defaults["imageClass"]+'" style="" />');
alert('Length: '+$('#divShadowLeft').length+' | Width: '+$('#divShadowLeft').width()+' | Visible: '+$('#divShadowLeft').css('visibility'));

View 3 Replies


ADVERTISEMENT

JQuery :: .width() Of Image Returning 0 On Load Event?

Oct 1, 2010

var img_large = new Image();
$(img_large).load(function () {
$(".image_enlarge_container").append(this);

[code]....

View 2 Replies View Related

Jquery :: Width() And Height() Returning Incorrect Values In IE?

May 28, 2010

jquery width() and height() functions are consistently returning the wrong values for the viewport size (i.e. $(window).width). Anyone know why..or what I can do to fix it?

View 3 Replies View Related

JQuery :: Height() And Width() Returning Incorrect Values In Opera?

Dec 13, 2007

I'm using height() and width() to find the dimensions of some inline images in the html. FF and IE work fine, but Opera is returning incorrect values. For example, it returns 92px as the width of an image that is actually 160px wide. How can I fix this?

View 4 Replies View Related

GetAttribute("width") Not Returning Correctly

Oct 31, 2006

I'm working on a slider script and it would be just lovely to be able to specify the slider's width in a width attribute on the input that represents it. In the code below, getAttribute("width") is returning 0 in IE, but seems to work fine in firefox. . . .

<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<head>
<script type="text/javascript">
var curr_slide="";
var ie = (document.all && !window.opera)?1:0;
if (!ie) document.captureEvents(Event.MOUSEMOVE)
var tempX = 0
var tempY = 0
var slide_width=200;
window.onload=function()
{
buildSlider();
}
function buildSlider()
{
var sliders=getElementsByClassName(document,'input','slider');
var len=sliders.length;
for(var i=0;i<len;i++)
{
var div=document.createElement('div');
div.className='slider_house'
alert(sliders[i].getAttribute('width'));
if(sliders[i].getAttribute('width'))
{
slide_width=sliders[i].getAttribute('width')*1;
}
div.style.width=(slide_width+10)*1+'px'
var handle=document.createElement('div');
handle.className='handle'
handle.style.left=&#390;px'
handle.onmousedown=function()
{
curr_slide=this;
document.onmousemove=function(e)
{
getMouseXY(e);
}
document.onmouseup=function()
{
document.onmousemove="";
}
}
div.appendChild(handle);
sliders[i].parentNode.insertBefore(div,sliders[i]);
}
}
function getSlide(obj)
{
var s=obj.parentNode;
var lft1=s.offsetLeft;
var lft2=obj.offsetLeft;
var num=(lft2-lft1)-1;
if(ie)
{
num=num-10;
}
return num;
}
function getElementsByClassName(oElm, strTagName, strClassName){
var arrElements = (strTagName == "*" && oElm.all)? oElm.all : oElm.getElementsByTagName(strTagName);
var arrReturnElements = new Array();
strClassName = strClassName.replace(/-/g, "-");
var oRegExp = new RegExp("(^|s)" + strClassName + "(s|$)");
var oElement;
for(var i=0; i<arrElements.length; i++){
oElement = arrElements[i];
if(oRegExp.test(oElement.className)){
arrReturnElements.push(oElement);
}
}
return (arrReturnElements)
}
function getMouseXY(e)
{
if (ie)
{
tempX = event.clientX + document.body.scrollLeft
tempY = event.clientY + document.body.scrollTop
}
else
{
tempX = e.pageX
tempY = e.pageY
}
if(tempX < 0)
{
tempX = 0
}
if(tempY < 0)
{
tempY = 0
}
n_spot=tempX-curr_slide.parentNode.offsetLeft;
var c_obj=curr_slide.parentNode.nextSibling;

while(!c_obj.nodeType==1)
{
c_obj=c_obj.nextSibling
}
if(c_obj.getAttribute('width'))
{
slide_width=c_obj.getAttribute('width')*1;
}
if(n_spot<=0)
{
n_spot=0;
}
else if(n_spot>slide_width)
{
n_spot=slide_width;
}
curr_slide.style.left=n_spot+'px'
c_obj.value=getSlide(curr_slide)*c_obj.getAttribute('alt');
}
</script>
<style type="text/css">
.slider
{
width:40px;
font-size:10px;
height:11px;
float:left;
}
.slider_house
{
clear:left;
float:left;
border-top:solid 1px #10385A;
border-left:solid 1px #FFFFFF;
border-right:solid 1px #FFFFFF;
margin-right:3px;
}
.handle
{
height:15px;
width:10px;
border-right:solid 1px #FFFFFF;
cursor:pointer;
position:relative;
left:0px;
border-left:solid 1px #FFFFFF;
background-image:url(images/triangle.gif);
}
table
{
width:100%;
}
table tbody tr td
{
border:solid 1px;
}
</style>
</head>
<body>
<br />
<form method="post">
<input type="text" alt="100" width="200" class="slider" />
<br />
<input type="text" alt="10" width="100" class="slider" />
<br />
<input type="text" alt="5" width="300" class="slider" />
<br />
<input type="text" alt="1" width="250" class="slider" />
<br />
<input type="text" alt="1000" width="50" class="slider" />
<br />
<input type="text" alt="2" width="500" class="slider" />
<br />
</form>
</body>
</html>

View 5 Replies View Related

JQuery :: Returning A Value From A Success Callback Function?

Jun 3, 2010

I know this is a simple question with a simple answer, but I can't seem to wrap my brain around it.Sorry for the infantile nature of this post. Anyhow, I am making an AJAX call via JQuery and need the function to return a value from a calling function, like so:

[Code]...

View 4 Replies View Related

JQuery :: Get Function Returning String Not JSON Object

Aug 5, 2009

I have a very simple PHP script that returns JSON like this:
{"question":"What day is it?"}

And I'm trying to call it from another page using Ajax. My code looks like this:
var url = "/test.php";
$.get(url,
function(data){
$.each(data, function(i, value) {
alert(value);
}, "json"
);
});

When I run it I get each character printed out one at a time in a separate alert. And then when I used this line of code:
alert(typeof data);
It tells me that 'data' is a string. Shouldn't it be a JSON object?

View 6 Replies View Related

JQuery :: Keydown Function Not Returning The Correct Keycodes

Jan 11, 2012

The event which in the following keydown function code is not returning the correct key codes. I have checked this in Chrome using the developer tools and the console.log(e.which) statement in my code.

var KEY = {
UP: 38,
DOWN: 40,
W: 87,

[Code]....

View 3 Replies View Related

Function Calling Function Returning False

Jun 7, 2010

I am trying to write a function that is being invoked when some one clicks the submit button on the form.<form name="sectionA" action="optionpage.cfm" onSubmit="return abc()">I have three tables with initials textboxes. I want to check if they are empty and return false(stay on the same page), else go to action page.Here is what I am doing, I Created three functions tableA(), tableB(),tableC() call them from function abc(). These functions tableA(), tableB(), tableC() return false if one of the field is empty and stop furthur processing and remain in the same page. If none(errors), then go the other page.i.e if table B has empty fields, page should stop furthur processing and remain in the same page.Here is how I am doing it Can somebody please point out what I am doing wrong here.Even when there is empty field, the code moves me to the actionPage.

View 2 Replies View Related

Function Not Returning Value / What To Do?

Mar 27, 2009

The following code is supposed to return a variable containing text, currently the code posts the data but returns an "undefined" variable. Can someone tell me what's wrong? code...

View 9 Replies View Related

Returning Value Outside Of Function?

Mar 27, 2009

I would like to document.write the status value using the return function but I can't get it to work.

The output should be Markers On or Markers Off.

<html>
<head>
<script type="text/javascript">

[Code].....

View 3 Replies View Related

Function Returning Wrong Value / Why Is So?

Feb 18, 2009

Why is my function returning the wrong value??

View 1 Replies View Related

Why Is Function Returning False?

Aug 13, 2011

So for whatever reason the convertToArray function in the following code returns false if the argument is more than 1 character long. If it's 1 character long it just returns the character as an array with only one value.What I'm trying to do is take a string of numbers, plus signs, and minus signs and convert it to an array.

View 5 Replies View Related

JQuery :: CSS Height / Width Function Value

Jul 20, 2009

Currently for the height and width functions, this is the description:

View 3 Replies View Related

Returning Form Field Name From Function

Nov 3, 2005

I have a little problem in one of my functions, I would like to pass in a form field name and set the value to something that is passed in. here is my code:

function pickitem(id,type){
opener.document.getElementById("form").type.value = id;
window.close()
}

so i'm passing in an id and a formfield e.g. txtName The problem is with the type.value - i haven't touched javascript for ages so i'm really rusty!!

View 12 Replies View Related

Ajax :: Returning A Value Directly From A Function?

Dec 1, 2009

I'm attempting to simplify my javascript code when it comes to ajax, but afterwords it only prints 'undefined' to the screen rather than what I want it to print.

I want to be able to put something like this on my main page onclick="document.getElementById('output').innerHTML = print_output();" where print_output() is the ajax function. This way I don't have to use a function to assign values directly to innerHTML and I don't have to muck about with a js file whenever I want to change my page layout.

To do this, I created a recursive function:

function print_output(return_value) {

if a value has been passed to the function, simply return it
if(return_value || return_value == 0) {
return return_value;
}

[Code].....

but like I said, it prints 'undefined' out to the screen. Why isn't this printing the contents that it receives from 'index.php' like it's supposed to?

View 2 Replies View Related

Returning Variable From Within Nested Function

Mar 9, 2009

The code is below but basically I have two global variables, then I have a function and then a function within that, I am simply trying to update these global variables from within the nested function so i can then go on and use them in another function! this sounds like quite a straight forward request to me, but maybe it can not be done? When I do an alert on the variables (after I have apparently updated their values) I get 'undefined'!

Code JavaScript:
var resultLatB;
var resultLngB;
function getLatLngFromTown(town, callbackFunction) {
var localSearchB = new GlocalSearch();
localSearchB.setSearchCompleteCallback(null,
function() {
if (localSearchB.results[0]){
resultLatB = localSearchB.results[0].lat;
resultLngB = localSearchB.results[0].lng;
pointA = resultLatB;
pointB = resultLngB;

//THIS WORKS
alert("Test 1 = " + resultLatB);
alert("Test 1 = " + resultLngB);
}});
localSearchB.execute(town + ", UK");
//DOESN'T WORK... SHOULD IT?
alert("Test 2 = " + resultLatB);
alert("Test 2 = " + resultLngB);
}
getLatLngFromTown("oxfordshire",null);

//I WANT THIS TO WORK!
alert("Test 3 = " + resultLatB);
alert("Test 3 = " + resultLngB);

View 4 Replies View Related

GetElement Function Returning Undefined Value

Sep 26, 2009

Here is a clip of code from a script project im working on. Now my document.getElementsByTagName is returning a "undefined" value.

<a href="[URL]" style="text-decoration: none; color: #EDDBAF; font-size: 16px;">
<center style="margin-left: 10px; margin-right: 10px;">
<font style="color: #EDDBAF; font-size: 16px;" id="title"></font>
</center></a>
<li id="name"><a http="[URL]" style="color: blue;">John Doe</a></li>
<script type="text/javascript">
var pname = document.getElementById('name').getElementsByTagName('a');

Now if I remove the ".getElementsByTagName('a')" it will actually work, but it also includes the <a> tag thats within the <li> tag, which I don't want.
document.getElementById('title').innerHTML=pname.innerHTML;
</script>

View 4 Replies View Related

Returning ResponseXML, Set Within An Anonymous Function, Only Once ReadyState = 4

Dec 4, 2006

I have several functions with code along the lines of:

var xmlDoc = requestXML("ajax.asp?SP=SelectRelatedTags&tag=" +
array[i]);

The requestXML() function includes the code:

var xmlDoc = null;
http_request.onreadystatechange = function() {
if (http_request.readyState == 4) {
if (http_request.status == 200) {
xmlDoc = http_request.responseXML;
} else {
alert('There was a problem with the request.' +
http_request.status);
}}};
http_request.open('GET', url, true);
http_request.send(null);
return xmlDoc;

However, the last line (the return) executes before the readyState
reaches 4. How do I return the xmlDoc to the functions only once the
xmlDoc has been assigned? I tried putting the return statement in a
while loop with the condition that the readyState must = 4 - this
worked, but makes the browser popup a message saying the script is
slowing down the system.

View 1 Replies View Related

3 Deep Function Call Not Returning To First / Resolve This?

Apr 23, 2010

I have a setup where I have a function, calling a function, calling a function. All functions do what they're supposed to do, but they don't return to the first function when all is done, so it doesn't display an alert that it's supposed to.

For those that don't want to look through tons of code and think they might know what I'm doing wrong, here's the "coles notes" version. code...

View 2 Replies View Related

Returning Text From ResponseText XMLHttpRequest Function?

Apr 23, 2010

I am wondering how can I return the variable senttext from the function below?I have declared it and when I alert(senttext) below it appears as I want it but I need to return it and pass it to another function. When I change alert() to return the variable becomes undefined?

var senttext;
function getData()
{
if (window.XMLHttpRequest) {

[code]...

View 6 Replies View Related

Script Function Returning Undefined / Sort It?

Oct 20, 2010

I have a function where in I call another function that assigns a value to a var. code...

For some reason my code below is returning 'undefined'. But when I place an alert(); before the 'return' it shows the correct value. However when I place an alert(); to show the var that is set to what the function returns it says 'undefined'.

Firebug throws no errors. I am using a little bit of jQuery.

View 10 Replies View Related

Returning Reference To Function Definition When Using Self-Invocation?

Mar 26, 2011

I have this code:

HTML Code:

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html>

[code]....

The practical scenario is I have several functions attached to the jQuery ajaxSucess event. Each function needs to execute once during initial load and after when the JQuery ajaxSuccess event is fired. So I am just looking to see if I can eliminate a a few lines of code and learn something new in the process, that is really all.

View 7 Replies View Related

Document.createElement Element - Remove 'div' Before Returning The Function

Apr 18, 2011

I've written the following small feature test.

[Code].....

I want to remove 'div' before returning the function. Testing in IE something like div.parentNode.removeChild(div); will fail. If I look in the dom 'div's parentNode is null, so that explains that. It needs to be appended to something first I guess.

View 1 Replies View Related

JQuery :: Calculate The Width Of Each Column Plus The Combined Width For The Container?

Apr 26, 2011

Is there any way that one could have supersubs functionality applied to drop-down multi-column menus?I assume one would need to calculate the width of each column plus the combined width for the container.

View 1 Replies View Related

JQuery :: All Images Must Be Resized If Width Exceeds Max Width?

May 5, 2010

I currently have a website where i share thoughts with my friends (some kind of forum) and within this 'forum' people can post pictures they made but most of the time these pictures exceed the max width of my website so my website gets all streched out!So this is what i want: all images on the page must run thru some sort of function which checks if the image image width exceeds the max_width. if it does then the script must calculate how many pixels the current width exceeds the max_width and get this number so that the script does: current_width = current_width - (max_width - current_width)

View 1 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved