on/off toggle in php

1,585 views
Skip to first unread message

nexx

unread,
Apr 8, 2012, 9:25:22 AM4/8/12
to iPhoneWebDev
First, thanks for iui developers for providing this nice webkit!

I can't figure out how to read/set an on/off switch using php. What
I'd like to do is simply generate a code that:
- illustrate in a on/off button the status of a device (example: reads
the device' state from a php variable like $device_status=1 (1=on,
0=off)
- if user tap the on/off button while it is off, it should call a URL
(ex: http://localhost/turn_on_device.php) to turn it on (and vice-
versa)

Would someone please post a code snippet illustrating how to do that?

thanks
V

Remi Grumeau

unread,
Apr 9, 2012, 5:53:32 AM4/9/12
to iphone...@googlegroups.com
On Sun, Apr 8, 2012 at 3:25 PM, nexx <nexx...@gmail.com> wrote:
First, thanks for iui developers for providing this nice webkit!

I can't figure out how to read/set an on/off switch using php. What
I'd like to do is simply generate a code that:
- illustrate in a on/off button the status of a device (example: reads
the device' state from a php variable like $device_status=1  (1=on,
0=off)

<div class="toggle" onclick="" <?php if($device_status==1) { echo toggled="true" } ?>>
  <span class="thumb"></span><span class="toggleOn">ON</span>
  <span class="toggleOff">OFF</span>
</div>
 
- if user tap the on/off button while it is off, it should call a URL
(ex: http://localhost/turn_on_device.php) to turn it on (and vice-
versa)

You need to add an Ajax call to the onclick event.
 

Would someone please post a code snippet illustrating how to do that?

thanks
V

--
You received this message because you are subscribed to the Google Groups "iPhoneWebDev" group.
To post to this group, send email to iphone...@googlegroups.com.
To unsubscribe from this group, send email to iphonewebdev...@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/iphonewebdev?hl=en.


nexx nexx

unread,
Apr 9, 2012, 6:00:36 PM4/9/12
to iphone...@googlegroups.com
On Mon, Apr 9, 2012 at 6:53 AM, Remi Grumeau <remi.g...@gmail.com> wrote:
On Sun, Apr 8, 2012 at 3:25 PM, nexx <nexx...@gmail.com> wrote:
First, thanks for iui developers for providing this nice webkit!

I can't figure out how to read/set an on/off switch using php. What
I'd like to do is simply generate a code that:
- illustrate in a on/off button the status of a device (example: reads
the device' state from a php variable like $device_status=1  (1=on,
0=off)

<div class="toggle" onclick="" <?php if($device_status==1) { echo toggled="true" } ?>>
  <span class="thumb"></span><span class="toggleOn">ON</span>
  <span class="toggleOff">OFF</span>
</div>
 
- if user tap the on/off button while it is off, it should call a URL
(ex: http://localhost/turn_on_device.php) to turn it on (and vice-
versa)

You need to add an Ajax call to the onclick event.


OK thanks.. I'll search google and try to find out how.

If anybody already did that on php please post the code!

Regards,
V
Reply all
Reply to author
Forward
0 new messages