7 Replies - 4456 Views - Last Post: 06 July 2010 - 02:53 PM

#1 quadrilateral  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-July 10

OnClick without javascript

Posted 05 July 2010 - 03:14 PM

Hi there.

I am trying to make a website and was hoping to code it in such a way that it works even when Javascript is disabled. So far it seems to be working except i need to find a way for events such as onclick to work even when Javascript is disabled. Is this possible? I have no working code and have met dead ends everywhere I look.

Any and all suggestions are welcome.

Thanks for your time.

Is This A Good Question/Topic? 0
  • +

Replies To: OnClick without javascript

#2 girasquid  Icon User is offline

  • Barbarbar
  • member icon

Reputation: 108
  • View blog
  • Posts: 1,825
  • Joined: 03-October 06

Re: OnClick without javascript

Posted 05 July 2010 - 03:17 PM

Unfortunately, this isn't possible - onclick is a javascript-only deal.
Was This Post Helpful? 1
  • +
  • -

#3 quadrilateral  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-July 10

Re: OnClick without javascript

Posted 05 July 2010 - 03:37 PM

Ok, thanks girasquid. Is there any other way to replicate onclick style features or is Javascript the only option for click events?

Thanks again.
Was This Post Helpful? 0
  • +
  • -

#4 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,259
  • Joined: 08-June 10

Re: OnClick without javascript

Posted 05 July 2010 - 11:09 PM

you could try Java Applets, but they depend on an installed JRE (Java Runtime Environment). If you ask me, stick to Javascript.
Was This Post Helpful? 0
  • +
  • -

#5 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: OnClick without javascript

Posted 06 July 2010 - 12:24 AM

Actually, if you give us an idea what you are trying to do we can possibly help.
You can't make a javascript event trigger without javascript, obviously, but think about what you're trying to achieve with the onclick and try do see how your page works without it. Unless you're writing something that's basically a JS app, there's no need for any script. The guiding principle here is to make a page and then go over it and make some things cooler if javascript is available.
Form validation can (and should) be done server-side as well as client-side. The window location should be changed with anchors and buttons not with javascript unless it's degradable. Animations should degrade. Sound effects should not exist.

Some effects can also be handled by CSS. For instance, clicking an input field to set its colour can be achieved using the selector input:focus.

Show us what you're trying to do.
Was This Post Helpful? 1
  • +
  • -

#6 Dormilich  Icon User is offline

  • 痛覚残留
  • member icon

Reputation: 3541
  • View blog
  • Posts: 10,259
  • Joined: 08-June 10

Re: OnClick without javascript

Posted 06 July 2010 - 01:12 AM

View Postmoopet, on 06 July 2010 - 07:24 AM, said:

Some effects can also be handled by CSS. For instance, clicking an input field to set its colour can be achieved using the selector input:focus.

additionally, mouseover (esp. rollover) effects can be done by using the :hover pseudo class (known examples are the "Suckerfish Dropdown" and "Image Sprites")
Was This Post Helpful? 0
  • +
  • -

#7 quadrilateral  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 10
  • Joined: 05-July 10

Re: OnClick without javascript

Posted 06 July 2010 - 02:06 PM

Thanks for the replies, I have tried using some of the CSS suggestions you made and they have helped in some areas.
I am trying to make a form for a website and wanted an area to be either invisible or disabled until you click on a checkbox. When the checkbox is ticked, the area is visible, when it is not it is invisible/disabled. Also I wanted to create a small script that updates a cost area every time a selection is clicked/changed. I got it all working with javascript but would like the form to be accessible to those who don't have javascript turned on. Is this possible or is there any way I could make this type of thing work without javascript, perhaps using CSS or server side. I can use PHP if necessary.
Was This Post Helpful? 0
  • +
  • -

#8 moopet  Icon User is offline

  • binary decision maker
  • member icon

Reputation: 339
  • View blog
  • Posts: 1,185
  • Joined: 02-April 09

Re: OnClick without javascript

Posted 06 July 2010 - 02:53 PM

Ah, ok.

The way forward is pretty straightforward:
Leave the area visible by default, and in javascript make a call to check and hide it iff the checkbox is unchecked as soon as the page loads. Combined with binding to the click event, that'll do it.

For example (using jquery because it's so much easier)
$(document).ready(function() {
    if ($('#mycheckbox:checked').length) {
        $('#myarea').hide();
    }

    $('#mycheckbox').change(function() {
        if ($('#mycheckbox:checked').length) {
            $('#myarea').show();
        }
        else {
            $('#myarea').hide();
        }
    });
});


Was This Post Helpful? 0
  • +
  • -

Page 1 of 1