www.webdeveloper.com
Results 1 to 5 of 5

Thread: [RESOLVED] Problem passing form name in Chrome and Firefox, not IE8

  1. #1
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    6

    resolved [RESOLVED] Problem passing form name in Chrome and Firefox, not IE8

    Hi there,

    I am using dynamically generated forms with (unknown) unique names and id's. When I want to pass the form id with javascript to a function, I receive a message from Chrome (in the javascript console) that it can not read the property id of null.

    I investigated this some more, and found that chrome and firefox are not passing the parameter this.form to a function correctly.

    A little sample code:
    <FORM name="variablename" id="variablename">
    <input type="text" name="variablename" id="variablename" onclick="test(this.form);"/>
    </FORM>

    (variablename stands for an automatically generated name which I can not literally state when calling the function)

    The javascript function 'test' looks like this:
    function test(form) {
    var formid=form.id;
    alert(formid);
    }

    Normaly a popup should arise stating the id of the form. In IE it works, but in Chrome and Firefox it doesn't.

    What am I doing wrong here?

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" 
    "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <title>Form ID</title>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <script language="JavaScript" type="text/javascript">
    function test(form){var formid = form.id; alert(formid);}
    </script>
    </head>
    <body>
    <form name="form_1" id="form_1" action="">
    <input type="text" name="variablename_2" id="variablename_2" onclick="test(this.form);" />
    </form>
    </body>
    </html>
    i just have tested this code in 3 browsers: IE6,FF and Opera. everything works good. your problem isn't here.
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

  3. #3
    Join Date
    Apr 2003
    Location
    Netherlands
    Posts
    21,654
    Can you give an example of how the form is generated?
    At least 98% of internet users' DNA is identical to that of chimpanzees

  4. #4
    Join Date
    Aug 2009
    Location
    Belgium
    Posts
    6
    I have figured out what was wrong. Padonak was absolutely wright. My problem was not the passing of this.form to the function, but was a mistake on my side of putting the form tag between the table "tag" and the first "tr" tag.
    When you do this, IE is still able to "form" tag, while mozilla isn't.

    I didn't mention it in the short code in this post, just to keep the code... short. My mistake again! Padonak, your remark made me strip the code down and test is bit by bit when suddenly...

    For those who are interested I wrote a little peace of wrong and wright code...

    WRONG CODE:
    <table>
    <FORM name="variablename" id="variablename">
    <tr>
    <td>
    <input type="text" name="variablename" id="variablename" onclick="test(this.form);"/>
    </td>
    </tr>
    </form>
    </table>

    WRIGHT CODE:
    <FORM name="variablename" id="variablename">
    <table>
    <tr>
    <td>
    <input type="text" name="variablename" id="variablename" onclick="test(this.form);"/>
    </td>
    </tr>
    </table>
    </form>

    Regards,

    Funzoh

  5. #5
    Join Date
    Mar 2011
    Posts
    1

    Post

    I just tested this, and it seems to work on Chrome 10.0.648.151.
    What seems weird is that in the application I am working on, it doesn't work.

    Can anyone else confirm it?

    Code:
    <table>
    	<form id="myForm">
    		<tr>
    			<td>
    				<input type="button" name="monBouton" value="A button..." onclick="alert(this.form.id);">
    			</td>
    		</tr>
    	</form>
    </table>
    Actually alerts 'myForm' as it should, but doesn't work in your case, right?

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles