RSS
 

Archive for November, 2012

Make the radio buttons behave like single-choice checkboxes

27 Nov

If you a web developer, maybe you encountered this annoying thing.

Let’s say you need to write a list of choices, i.e. questions – answers. Let’s define that all the questions are optional and you can select just one answer per question. The way you should implement it, is using inputs with radio type, that’s fine and this how it should be.
Example code is:

1
2
3
4
5
6
7
8
9
10
11
<form method="post">
    <h4>What is favorite time?</h4>
    <label><input type="radio" name="question1" value="morning" /> Morning</label>
    <label><input type="radio" name="question1" value="noon" /> Noon</label>
    <label><input type="radio" name="question1" value="evening" /> Evening</label>
    <h4>What is your preferable paying method?</h4>
    <label><input type="radio" name="question2" value="cc" /> Credit Card</label>
    <label><input type="radio" name="question2" value="check" /> Check</label>
    <label><input type="radio" name="question2" value="paypal" /> Paypal</label>
    <label><input type="radio" name="question2" value="cash" /> Cash</label>
</form>

Read the rest of this entry »

 

PhoneGap – Detect if the application runs on mobile or browser using JavaScript before the “deviceready” and document “ready” events are triggered

05 Nov

I spent hours to find out how to do it. And believe me or not, I found nothing on the whole internet about how to solve it.

Actually there is a simple way to do that after the event “deviceready” has been triggered (as described on the PhoneGap’s API Docs), it is simple as:

1
2
3
4
5
6
7
document.addEventListener("deviceready", function(e){
if ( device ) {
alert("Running on PhoneGap!");
} else {
alert("Running NOT on PhoneGap!");
}
}, false);

Read the rest of this entry »