Closed Thread Icon

Topic awaiting preservation: onclick to submit form from XHTML 1.1 doc (Page 1 of 1) Pages that link to <a href="http://ozoneasylum.com/backlink?for=26188" title="Pages that link to Topic awaiting preservation: onclick to submit form from XHTML 1.1 doc (Page 1 of 1)" rel="nofollow" >Topic awaiting preservation: onclick to submit form from XHTML 1.1 doc <span class="small">(Page 1 of 1)</span>\

 
Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-07-2005 03:38

I've got an XHTML 1.1 doc, served with application/xhtml+xml MIME type.

In it, I have an anchor like this

<a href="mypage.htm" onclick="document.icpyqt.submit();">blah</a>

The idea being that the onclick event should fire when clicked on from a javascript compliant browser (in my case, FF 1.04).

Anyways, looks like I'm ending up at the mypage.htm instead of the form being submitted. No errors.

Is anyone aware of javascript issues when using XHTML 1.1 served as application/xhtml+xml?

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-07-2005 04:33

return false; at the end of the onclick event.


 

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-07-2005 04:45

That didn't do it. It still just goes to the href.

I could have sworn that I read something, somewhere, about javascript working a little differently when served as application/xhtml+xml.....

I'm still looking.

Thanks.

UPDATE: document.getElementById('myform').submit();return false; worked. I read that getElementById() is the preferred way when using application/xhtml+xml.

Thanks!



(Edited by Pugzly on 07-07-2005 04:53)

poi
Paranoid (IV) Inmate

From: France
Insane since: Jun 2002

posted posted 07-07-2005 08:33

I remember I read somewhere that document.idOfAnElement should also work in standard compliant browsers but I definitely prefer to stick to something that does work : document.getElementById( 'idOfAnElement' )

Slime
Lunatic (VI) Mad Scientist

From: Massachusetts, USA
Insane since: Mar 2000

posted posted 07-07-2005 08:47

Oh, I see. You weren't getting an error message?

I think the proper way (without using getElementById) is something like document.documentElement.body.idOfAnElement - you have to actually specify the path to the node in the document. (May be wrong.)


 

kryogenix
Obsessive-Compulsive (I) Inmate

From:
Insane since: Jul 2005

posted posted 07-07-2005 09:19

Try attaching the onclick handler from JavaScript with addEventListener()/attachEvent() rather than using an inline handler; that's likely to help matters, and be more future-proof to boot because you don't have to change the HTML later. (Is onclick a recognised attribute in properly-compliant XHTML?)

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

posted posted 07-07-2005 11:00

I kinda agree with Kryogenix but I'm not sure if I'm thinking the same thing I'm thinking, seperate the behaviour from the content, just as you seperate the presentation from the content. using onclick attributes is much the same as using the style="" attribute.

Jeremy Keith is a wizard with Javascript and his written an article called this years DOM model it's really useful and explains a really neat way that javascript can be totally seperated from the content. Remeber that the class attribute wasn't made initially for CSS, it's actually for the DOM just as id is.

The last few pages really explain what I'm talking about.

Cheers,

Pugzly
Paranoid (IV) Inmate

From: 127.0.0.1
Insane since: Apr 2000

posted posted 07-07-2005 20:17

Slime -
No - I wasn't getting an error. The document.getElementById method resolved it, and after that, I did read that that is the correct method for XHTML 1.1

kryogenix - Yes, you can use the onclick event in 1.1

Blaise - Thanks for the link. I'll keep it handy. I don't usually have to do too much javascript stuff.....

I haven't done much cross-browser testing on the page yet. Is the document.getElementById method going to give me any surprises?

Blaise
Paranoid (IV) Inmate

From: London
Insane since: Jun 2003

posted posted 07-07-2005 23:14

document.getElementById will work with the current generation of browsers, but instead of doing a browser test do a test by objects before running your code, therefor if the object exists in the DOM the browser will continue

code:
function myFunc(){
  if(!document.getElementbyId()){
    return false;
  else{
    alert('yay it works')
  }
  }
}

It's explained properly in that link I gave you before to Jeremy Keiths website.

Hope this helps.

Cheers,

Blaise.

« BackwardsOnwards »

Show Forum Drop Down Menu