Current location: Hot Scripts Forums » General Web Coding » JavaScript » New to javascript and FF


New to javascript and FF

Reply
  #1 (permalink)  
Old 12-20-07, 02:19 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Post New to javascript and FF

Hi everyone and merry christmas.

I am having problems with trying to make my website support various browsers. I have some cool functions which I have created using javascript. Im new to javascript so my code may or maynot be up to standards so please be patient and bit your tounges if you see anything Im being stupid about.


I want to have a check box which when turned on disables a few boxes. IE works fine with the code I have but firefox just sits there with a blank expression.

basically;

javascript function grayout
Code:
function grayout(onoffelement,groupid)
{
    var stateofbox = onoffelement.checked;
    if(stateofbox == false)
    {
        document.getElementById('inpText['+groupid+']').style.backgroundColor="#FFD543";
        document.getElementById('inpText['+groupid+']').disabled=false;
    }
 
    if(stateofbox == true)
    {
        document.getElementById('inpText['+groupid+']').style.backgroundColor="#EDEDED";
        document.getElementById('inpText['+groupid+']').style.backgroundColor="#EDEDED";
    }
 
}

Code:
<input type="checkbox" name="box[0]" id="box" value="somevalue" onClick="javascript:grayout(this.form.box[0],'0');">
 
<input type="checkbox" name="box[1]" id="box" value="somevalue" onClick="javascript:grayout(this.form.box[1],'1');">
It seems that IE works fine with the form array elements but FF doesnt. I build this all through a php function which has a far more complicated result than this but FF doesnt seem to support arrays for text boxes. IE just does it.

FF and IE both work for single elements of form entities which isnt dynamic enough for my needs. Is there an option like;
Code:
firefox.stupid=false;


Thanks in advance
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #2 (permalink)  
Old 12-20-07, 06:48 AM
Nico's Avatar
Nico Nico is offline
Community Leader
 
Join Date: Sep 2005
Location: Spain
Posts: 8,075
Thanks: 11
Thanked 88 Times in 83 Posts
Instead of this.form.box[0], use just this. This will referrer to the element without using array brackets.

And you can take out the "javascript" in:
Code:
onClick="javascript:grayout
The browser will only expect Javascript there, so there's no need to tell him.
Code:
onClick="grayout(...
Reply With Quote
  #3 (permalink)  
Old 12-20-07, 11:11 AM
DAL's Avatar
DAL DAL is offline
Code Master
 
Join Date: Jun 2003
Location: North East England/UK
Posts: 874
Thanks: 0
Thanked 0 Times in 0 Posts
Thanks Nico

The problem isnt with the respective control over the tickbox array but that of the array for the other boxes I want to disable. There are 8 other text boxes which need the attribute set to disable=true; when the box is checked. When the box is unchecked the text boxes are set to disable=false; IE can understand this but FF cant and I believe its down to the array element.

EG
var test = document.getElementById('inpText['+groupid+']').disabled;

alert(test);

will result in IE producing the value true or false in an alert box.
FF wont do a thing (not even poping up an alert box)

if I asked firefox to do the same with an element accessed via true text hard coding;
EG
var test = document.getElementById('inpText[1]').disabled;

alert(test);

it would show the value in an alert box. But what point would that be as I would know what value was being passed. Theres no way that Im going to hard code everything with functions for every option as the code would be huge. Dynamic ranges are accepted in IE, so why does FF have such a problem reading them?
__________________
"once upon a midnight dreary, while i pron surfed, weak and weary, over many a strange and spurious site of 'hot xxx galore'. While i clicked my fav'rite bookmark, suddenly there came a warning, and my heart was filled with mourning, mourning for my dear amour," 'Tis not possible!", i muttered, "give me back my free hardcore!" quoth the server, 404."
Reply With Quote
  #4 (permalink)  
Old 12-21-07, 03:32 AM
UnrealEd's Avatar
UnrealEd UnrealEd is offline
Community Liaison
 
Join Date: May 2005
Location: Antwerp, Belgium
Posts: 3,165
Thanks: 4
Thanked 25 Times in 25 Posts
this probably won't work either, but just give it a shot:
Javascript Code:
  1. function grayout(onoffelement,groupid)
  2. {
  3.     var stateofbox = onoffelement.checked;
  4.     var inputName = 'inpText[' + groupid.toString() + ']';
  5.     if(stateofbox == false)
  6.     {
  7.         document.getElementById(inputName).style.backgroundColor="#FFD543";
  8.         document.getElementById(inputName).disabled=false;
  9.     } else {
  10.         document.getElementById(inputName).style.backgroundColor="#EDEDED";
  11.         document.getElementById(inputName).style.backgroundColor="#EDEDED";
  12.     }
  13.  
  14. }
I just searched the web for a while, and i saw that the disabled attribute of any element should look like this (probably only if you're working with XHTML):
HTML Code:
<input type="text" disabled="disabled" />
So setting the attributes value to "true" might not disable the textfield. Try setting the value to "disabled", like this:
Javascript Code:
  1. function grayout(onoffelement,groupid)
  2. {
  3.     var stateofbox = onoffelement.checked;
  4.     var inputName = 'inpText[' + groupid.toString() + ']';
  5.     if(stateofbox == false)
  6.     {
  7.         document.getElementById(inputName).style.backgroundColor="#FFD543";
  8.         document.getElementById(inputName).disabled = "disabled";
  9.     } else {
  10.         document.getElementById(inputName).style.backgroundColor="#EDEDED";
  11.         document.getElementById(inputName).style.backgroundColor="#EDEDED";
  12.     }
  13.  
  14. }
__________________
"Good judgement comes from experience, and experience comes from bad judgement." - Fred Brooks

Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
how do i remove active link border in IE and FF kaos_frack CSS 2 10-15-08 10:07 PM
javascript not working in FF & Opera bitstomper JavaScript 6 05-27-07 07:14 PM
Javascript Date/Time thirdwatch4 JavaScript 1 12-03-06 01:57 PM
Resize browser window for FF and IE pcinfoman JavaScript 1 05-04-06 02:47 PM


All times are GMT -5. The time now is 11:33 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.