SitePoint Sponsor

User Tag List

Results 1 to 12 of 12

Hybrid View

  1. #1
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.formname has no properties !!!

    Well, I'm getting an error. Here is the function, what, according to FF's consolde is generating the error.

    Code JavaScript:
    function citizen3()
    {
    	if (document.ededfil.nationalite[0].checked == true) {
    	document.ededfil.pays_origine[0].checked = true;
    	document.ededfil.pays_origine[0].disabled = true;
    	document.ededfil.pays_origine[1].disabled = true;
    	document.ededfil.pays_origine[2].disabled = true;
    	} else if (document.ededfil.nationalite[1].checked == true) {
    	document.ededfil.pays_origine[0].checked = false;
    	document.ededfil.pays_origine[0].disabled = false;
    	document.ededfil.pays_origine[1].disabled = false;
    	document.ededfil.pays_origine[2].disabled = false;
    	}
    }

    The line getting selected by the FF console is
    Code JavaScript:
    if (document.ededfil.nationalite[0].checked == true) {

    The line that's calling the function is -

    Code PHP:
    <input type="radio" name="nationalite" <? If ($nationalite == "Française") { ?> checked <? }?> value="Française" onClick="citizen3();">&nbsp;&nbsp;&nbsp;Autre&nbsp;&nbsp;&nbsp;<input type="radio" name="nationalite" <? If ($nationalite == "Autre") { ?> checked <? }?> value="Autre" onClick="citizen3();">

    Can anyone see what's the problem?

    The error is - document.ededfil has no properties.

    Thanks.

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please post the start tag for the form.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Evangelist hexburner's Avatar
    Join Date
    Jan 2007
    Location
    Belgium
    Posts
    591
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Most browsers allow you to use document.formname.inputname, but some browsers refuse to do this thing right. Beats me why.

    You could use document.form[0] if it's the first form in you page, or if it's the second form you use an index of 1.
    Or you can use document.getElementById('formid')
    FOR SALE: 1 set of morals, never used, will sell cheap

  4. #4
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    (Assuming that your form has the name or ID "ededfil") You simply need to include the forms collection:
    Code:
    document.forms.ededfil
    IE allows you to not specify collections, because it can find all elements with a name or ID in its document.all collection, but other browser don't do this (as well they shouldn't, but that's a more convoluted story!)

  5. #5
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Kravvitz, the start tag of the form is -
    Code PHP:
    <form name="ededfil" id="ededfil" method="post" action="<?=$_SERVER['PHP_SELF']?>" enctype="multipart/form-data">

    In IE7, I'm getting a yellow alert at the left of status bar, on clicking which I am getting an error saying -

    Code JavaScript:
    document.ededfil.nationalite is null or not an object

    brothercake, added the forms.ededfil, same result.

    hexburner, I can't use document.form[0] as I'm calling that from an external javascript file, which is common to all files ... and the following getelementbyid gives me 'Object required' error in IE7, and myKKK has no properties in FF console.

    Code JavaScript:
    function citizen3()
    {
    	var myKKK = document.getElementById('ededfil');
    	if (myKKK.nationalite[0].checked == true) {
    	myKKK.pays_origine[0].checked = true;
    	myKKK.pays_origine[0].disabled = true;
    	myKKK.pays_origine[1].disabled = true;
    	myKKK.pays_origine[2].disabled = true;
    	} else if (myKKK.nationalite[1].checked == true) {
    	myKKK.pays_origine[0].checked = false;
    	myKKK.pays_origine[0].disabled = false;
    	myKKK.pays_origine[1].disabled = false;
    	myKKK.pays_origine[2].disabled = false;
    	}
    }
    Last edited by kigoobe; May 31, 2007 at 03:55.

  6. #6
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Are you sure the form exists at the point when you're referencing it? For example, code in the HEAD section that isn't tied to an onload or similar ready-state function, won't be able to reference an element in the BODY, as it hasn't been rendered yet.

    What does the whole page look like?

  7. #7
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Good point brothercake.

    Well, I have a page where people are posting data. Now in case the page is submitted, with some required fields blank, this form appears. DO you think that's the issue here? If that's the case, do you have any workaround?

    The page is having 650 lines of code, should I post something that big here ?

    Edit:

    After a second thought, this seems to be the most reasonable reason here ... is there a workaround to this problem ?

  8. #8
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Like,

    Code JavaScript:
    if (some php conditions are met) {
      //do something and call that function onclick
    } else {
      //do otherthings and also do something so that I don't get the ...has no properties  error.
    }

    What do you think here guys ... is this possible?

  9. #9
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Just put the <script> in the page so that it comes after the end of the form - after the closing </form> tag.

  10. #10
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You mean, I take out that function from my externel javascript file, and paste it after the closing of </form> ?

  11. #11
    Always learning kigoobe's Avatar
    Join Date
    May 2004
    Location
    Paris
    Posts
    1,565
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    yes, you are right, this is what I should do ... ... hope that will solve the issue .. thanks a lot for your time.

  12. #12
    SitePoint Guru
    Join Date
    Mar 2004
    Location
    Earth
    Posts
    406
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Keep it in the external file, but put the <script> include after the </form>


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •