CodingHTML radio buttons

 

Press Ctrl+Enter to quickly submit your post
Quick Reply  
 
 
  
 From:  af (CAER)  
 To:  Radio      
38188.91 In reply to 38188.90 
Once again, it's an issue with IE, in this case not supporting the previousElementSibling property. Change it to previousSibling and it works fine. I've only tried it in IE8, dunno about 7 or 6.
0/0
 Reply   Quote More 

 From:  Radio   
 To:  ALL
38188.92 
I'm only worried about 8, and all seems to work fine now - thanks.
My life is hard, I suffer lots
0/0
 Reply   Quote More 

 From:  Radio   
 To:  ALL
38188.93 
Using the function supplied earlier, some of the numbers coming in are in the thousands, and have helpfully been formatted to include comma separators.
I found a snippet of javascript that removes commas, but it doesn't seem to work. Anyone care to have a go at explaining what I've done wrong this time? ;-)

javascript code:
<script type="text/javascript">
//Get the values from the table when checkboxes are checked
var getCheckboxes = function () {
    var i, elements = document.getElementsByTagName("input"),
        max = elements.length,
        result = [];
 
    for (i = 0; i < max; i += 1) {
        if (elements[i].type === "checkbox") {
            result.push(elements[i]);
        }
    }
    return result;
    DeleteComma(result);
};


javascript code:
<script type="text/javascript">
function DeleteComma(num) {
var temp1 = 0;
var xarray = num.split(",");
if ( xarray[2] != null ) {
   temp1 = xarray[0]+xarray[1]
+xarray[2]; return temp1 } 
else if ( xarray[1] != null ) {
          temp1 = xarray[0]
+xarray[1]; return temp1}
       else
{temp1 = xarray[0]; return temp1 }         
}
</script>
My life is hard, I suffer lots
0/0
 Reply   Quote More 

 From:  af (CAER)  
 To:  Radio      
38188.94 In reply to 38188.93 
Um, that seems like a vastly over-complex function just for removing commas from a string.
javascript code:
var deleteCommas = function (num) {
    return (num + "").replace(/,/g, "");
};

But aside from that, you're calling DeleteComma() on the result of a function that generates a list of checkboxes. There are no commas to delete from such a list. Moreover, you'e calling it after the function has returned, so it never actually gets exectuted.

edit:
Looking over the code, the bit you need to change is this loop:
javascript code:
for (i = 0; i < max; i += 1) {
    if (checkBoxes[i].checked) {
        // Get values directly from table cells.
        total += +checkBoxes[i].parentElement.
            previousElementSibling.innerHTML;
        totalWholesale += +checkBoxes[i].parentElement.
            previousElementSibling.previousElementSibling.innerHTML;
    }
}
Change it to this:
javascript code:
var element, deleteCommas;
 
deleteCommas = function (num) {
    return (num + "").replace(/,/g, "");
}; 
 
for (i = 0; i < max; i += 1) {
    if (checkBoxes[i].checked) {
        element = checkBoxes[i].parentElement.previousSibling;
        total += +deleteCommas(element.innerHTML);
 
        element = element.previousSibling;
        totalWholesale += +deleteCommas(element.innerHTML);
    }
}


edit again:
Actually to make it even more resilient, you could change deleteCommas() to:
javascript code:
stripNonNumeric = function (num) {
    return (num + "").replace(/[^0-9.]/g, "");
};
That way it would remove things like currency symbols or extra spaces or whatnot - anything that isn't a digit or a .
0/0
 Reply   Quote More 

 From:  Radio   
 To:  af (CAER)     
38188.95 In reply to 38188.94 
Cheers - much appreciated once again!
My life is hard, I suffer lots
0/0
 Reply   Quote More 

Reply to All    
 

1–20  …  41–60  61–80  81–95

Rate my interest:

Adjust text size : Smaller 10 Larger

Beehive Forum 1.5.2 |  FAQ |  Docs |  Support |  Donate! ©2002 - 2024 Project Beehive Forum

Forum Stats