Script Goes Haywire When Two Of Three Elements Return 0
Sep 27, 2009
So my code is supposed to retrieve three values from a flash element. Now it works fine, but when it retrieves a 0 from any of the three valuse, it goes all haywire. How could I put in a statement or command that if it returns 0, that all it will display is a 0 instead of returning "NaN"? But since all three valuse added together are supposed to equal 100% i have to run the numbers through a little bit of division and rounding after it gets the value of each one.
var techfaction = document.getElementById('tfaction');
var natfaction = document.getElementById('nfaction');
var magfaction = document.getElementById('mfaction');
retrFaction();
roundNumber();
function retrFaction()
{
var values = document.documentElement.innerHTML.match(/factiontrianglesmall.swf??.*\x26link/i)[0].match(/[0-9.]{4,9}/ig);
techfaction.innerHTML = roundNumber(values[0] / 30, 1) + '%';
natfaction.innerHTML = roundNumber(values[1] / 30, 1) + '%';
magfaction.innerHTML = roundNumber(values[2] / 30, 1) + '%';
}
function roundNumber(num, dec)
{
var result = Math.round(num*Math.pow(10,dec))/Math.pow(10,dec);
return result;
}
View 2 Replies
ADVERTISEMENT
Jul 24, 2011
I am working on a function where I need to return the active elements ID. The element will have:
class="main" id="1" onmouseover="showSub()">
Would someone be able to write me a simple function which simply puts the elements ID number in an alert box?
View 6 Replies
View Related
Oct 23, 2009
I have nested markup like this
Code HTML4Strict:
<li><span></span></li>
I have different click functions, one attached to the li and the other to the span.
When I click on the span they both run. Ending the span's event handler with return false; prevented that from happening, which is what I want. But I'm not sure I understand why it worked.. I know, for example, if I was clicking on an anchor, return false would stop the browsers default action of following the href value. Same for submitting a form, return false will stop this. I don't think I understand why this would stop a completely different function from being triggered..
View 7 Replies
View Related
Jun 3, 2010
All is on the title, sorry for my english, i'm french :) I have an html page with style
<style>
#mydiv {
margin-left:auto;
margin-right:auto;
width:250px;
}
</style>
with jquery, i try to get the margin-left ($('#mydiv').css('margin-left'), but the function return 0px, unable to retrieve the good value (auto) anyone has idea to retrieve the value "auto" when margin-left is "auto" ?
View 1 Replies
View Related
Mar 14, 2010
I have a page I am working and I am having some trouble with: I need to show and hide areas based on a radio selection. I initally started using the show / hide feature in Jquery but the problem is the elements need to be removed but then put back if the user selects the radio buttonagain as it has form elements that have validaion on them. The validation is still trying to validate the form elements becuase they are still on the page but just not showing. This is the radio group the user makes the selection from:
<input name="terms_usr" type="radio" id="terms_usr_1" value="1"/>
<label for="terms_usr_1">Credit Card</label>
<input type="radio" name="terms_usr" id="terms_usr_2" value="2"/>
<label for="terms_usr_2">C.O.D</label>
[Code]....
View 3 Replies
View Related
Jun 3, 2010
I have HTML tags stored in XML. I want to be able to use these HTML elements with Javascript, just as you can with elements in document.body. How can it be done? (And don't try and tell me I should use server-side because I have written it all for Javascript and the project is nearly complete minus this and there are practical reasons for not doing this server-side. After all, anything is possible with Javascript!)
Let me explain:
- I have HTML templates such as this [URL]
- I want javascript to populate these templates then add them to my page
- The only way I know javascript can get this kind of data is by parsing XML
- I want to parse the XML then be able to use the HTML elements just like those in document.body
- As far as I'm aware, XML is the only good way of storing data for javascript. I don't want to store it in javascript variables (too much multiline data with " and '). Nor do I want to build it using document.createElement("div")... etc
As someone not yet with any experience in computer science etc, please ignore my poor terminology! However, I'm not a beginner when it comes to javascript.
Here's the script concerned but I doubt it'll help you understand my problem: [URL]
View 6 Replies
View Related
May 24, 2010
So i've got a form that adds an element onto the page. This is working. When I try to remove said elements, that works. But the same 'delete' button doesn't work on elements not generated by javascript.
Code JavaScript:
function destroyQuickTask() {
$.post($(this).attr("href"), null, null, "script");
[code]....
View 6 Replies
View Related
Jan 14, 2011
I have this in my javascript code but have no idea on how a returned value works/where does it return to? what do i do/or can i do with a value that gets returned?
I am asking this so i can learn on how to use it cos i am new to all this and dont know how it works...
Here my full code:
View 6 Replies
View Related
Oct 13, 2005
Do you have to use the onClick attrib to have
return false
work?
i.e. is it possible to do
<a href="javascript:somefunct();return false;">
and have the page not reload with 'false' or the browser not complain about
illegal use?
View 2 Replies
View Related
Jan 17, 2007
I have a form on a web page that requires to click on a button to
submit the information. I have two questions about changing this form:
1. Is there a way that I can change the script so that the form can be
submitted by hitting the enter key?
2. Is there a way that I can have the Username and Password boxes
cleard after the form is submitted?
You probably don't need the code for the form as it is pretty basic but
here it is just in case.
<form name=login>
<table width=225 border=1 cellpadding=3>
<tr><td colspan=2><center><font size="+2"><b>Bombers Only
Area!</b></font></center></td></tr>
<tr><td>Username:</td><td><input type=text name=username></td></tr>
<tr><td>Password:</td><td><input type=password name=password
size="20"></td></tr>
<tr><td colspan=2 align=center><input type=button value="Login!"
onClick="Login()"></td></tr>
</table>
</form>
View 3 Replies
View Related
Aug 1, 2009
i am using ajax but this is the problem in js it is giving me a NaN when i goto check the output. on two different servers two different responses on my localhost test environment i am getting the correct info and on the server online i get NaN response. i am using this to set the width of my hp bar
Code:
document.getElementById("ehpBar").style.width=count1+"%";
and count1 looks like this
Code:
var count1 = hp/basehp*100;
i have tried rounding it and everything and i just get the same stupid NaN error. I can use each variable by itself and it outputs the correct number on both servers and then when i try to divide it NaN on one server and works perfectly on the other. I know it is probably something simple i am just missing it.
View 1 Replies
View Related
Jan 27, 2009
I am using BBcodes and want to allow the client to enter their image url into an alert box.
Exactly as it is done in this forum ;)
[URL]
is this using a javascript alert box or a pop up window? How do I put the input box into it ?
View 7 Replies
View Related
May 17, 2009
Afternoon all, Have a pretty simple function, that requests a number to be entered.
I want to return that number, but i seem to be typing something wrong in the return value.
function newFunction(a, b)
{
var newArray = new Array(a);
for (var i = 0; i < 5; i = i + 1)
[Code]....
View 12 Replies
View Related
Sep 29, 2009
Its a ads rotation code:
Dont know why it doesnt work...
Here go(k); function might do this mass (output-->NaN).
View 3 Replies
View Related
Aug 21, 2007
I am populating a field on my page using a php include. I am asking javascript to update another element with that field's value. The value written to the select input box is Ƈ:Any Provider'. The process works fine in Firefox. In IE6 it does not write. the value nor does it throw an error. What am I doing wrong?
input form:
[PHP]<form method="post" action="" name="inputForm">
<label for="provider">Name of Provider</label><select class="input" name="provider" size="1" style="width: 20em"><?php nameprov();?></select>
<input type="button" name="button" value="Upload" onclick="postthis()">
<div id="status"></div>
</form>
The script in the head element:
function postthis(){
var provider = document.inputForm['provider'].value;
var report = document.getElementById("status");
var message="The Value of Provider Block is: " + provider;
report.innerHTML = message;
}
In firefox, "The Value of Provider Block is: 1:Any Provider" is written in the report element. In IE6, "The Value of Provider Block is : " is written in the report element.
View 7 Replies
View Related
Nov 23, 2005
I know the answer must be yes, but I am really having a hard time figuring this out. I have a simple script below, that calculates age (I know I need to do some more work). I want to redisplay the value returned from the function. It works OK, because the result displays correctly in the alert. Code:
View 23 Replies
View Related
Feb 27, 2006
I'm having a problem. I was able to get the edit working fine. I was able to get it to hide the current div and go to a different div. When I combine the two, the edit works but I cannot go to the different div.
I'm thinking something is missing here?
function goto_testDiv()
{
return formCheck(this);
document.getElementById('startDiv').style.display = 'none'
document.getElementById('testDiv').style.display = 'block'
}
View 4 Replies
View Related
Mar 6, 2006
I have a form and a submit button .on clicking submit button function validate call.this function call another function (say func) .this func function vallidates some input and return true or false value to the validate function this then return true or false value to the submit button .I want that func directly return true or false to the submit button.
View 2 Replies
View Related
Jun 13, 2011
How can I use the return value from prev_picked() in my ajax call?
Code JavaScript:
function autosuggest_results (info)
{
if (info.length > 1)
[Code].....
View 1 Replies
View Related
Apr 29, 2004
PHP Code:
function mnu() {
var thismenu=this;
var mDiv = document.createElement("div");
mDiv.getVisibility=function() { thismenu.getVisibility(this); }
alert(mDiv.getVisibility());
document.body.appendChild(mDiv);
}
mnu.prototype.getVisibility=function(div) {
if (div.style.visibility=='none' || div.style.visibility=='hidden') {
return 'hidden'
}
else {
return 'visible'
}
}
so i attach a function to mDiv, which (should) return visible or hidden, but it doesn't, i get an undefined
but when i put alert boxes in the function itself (in the if-clause), it gives me the correct values....
View 2 Replies
View Related
Jan 8, 2007
when, inside a function, one simply says:
if(...) {return;},
one means something like exit, or leave, right?
View 2 Replies
View Related
Apr 18, 2006
Is it necessary to return a value from the event handlers? For
instance, what does the return value in the following code signify?
What will be its impact if it returned otherwise (true)?
<a href="http://www.w3schools.com"
onmouseover="alert('An onMouseOver event'); return true">
<img src="Click.gif" width="100" height="30">
</a>
View 9 Replies
View Related
Jul 11, 2006
Can javascript using pointer or pass variable by reference?
Or I need to using object or Array to return the two values?
View 2 Replies
View Related
May 18, 2007
I have been working on this for a few hours and am frustrated
beyond all extent. I have tried to research this on the web as well
with no success. I am trying to match certain contents within a
wrapper div. So for example if the inside of the wrapper div was the
following:
<div id="wrapper">
<a href="#">a great link that contain text and symbols</a>
<div... </div>
<div... </div>
</div>
I would like to strip out all the internal div's. But because there
can be alot of internal div's, I figured it would be less processor
intensive to just match the first 'a' tag and repopulate the wrapper
div with the match. I am trying to use something like the following
regex:
re = /^<a(.+)</a>/;
with the following statment:
$temp = document.getElementById('wrapper').innerHTML.match (re);
but this is returning the entire contents of the wrapper div. I have
tried variations of the regex and either continue to get the entire
contents or null returns. Any help would greatly be appreciated.
BTW, I can't match to the first because the contents may be touching (ie ...</a><div>...).
View 3 Replies
View Related
May 22, 2007
This JS limits the input characters into the form. How do I modify it
so that it also allows CARRIAGE RETURN and BACKSPACE (for making text
correction)?
Due to the template engine I am using, I cannot use IF/ELSE statement.
<form>
<textarea name="event_description" ONKEYPRESS="if (document.layers)
var c = event.which;
else if (document.all)
var c = event.keyCode;
else
var c = event.charCode;
var s = String.fromCharCode(c);
return /[0-9a-zA-Zs,.?!@#$%&*()-]/.test(s);"></
textarea>
</form>
View 1 Replies
View Related
Mar 4, 2010
alert($(
"ul li").get(0));
Thisalert show this, literally: [object] This [object] will not accept any DOM methods like addClass, etc
View 6 Replies
View Related