Hell Yeah!

Found the blog again. At least someone is still alive. Post is coming up. Here’s a teaser:

You head south down the street.

`,RC||`,`,  Walker and Norton (slagtown) 2:26am
`,`,||G!AN  The shattered concrete ambles at odd angles through the smashed
`,`,()====  buildings, complementing the bent and rusted light poles to make
`,<>||ISCB  a bizarro caricature of a street.  Cold stars glitter in the night
==CP||NK`,  sky.  Thin cold rain drizzles from the dead sky.
           On the east horizon you can make out the smokestacks of a distant
 factory.  The ramshackle hulk of the Bradbury rises above the desolation to
 northeast.
 The street runs north, east, south, and southwest.  An open manhole leads
 down into the sewers.
 An ancient pay phone stands on the corner. 

A shabby monkey is standing here.
[ Exits:  north  east  south  southwest  v down ]
k mon
You start attacking the shabby monkey.
Rayne calmly lines up her 9mm Beretta at the shabby monkey.
The shabby monkey attacks you!
The shabby monkey lunges wildly at Rayne, fangs slavering.
[R##s][  66%] The shock of Rayne's shot shudders through the shabby monkey.
[R###s][  6%] The shabby monkey screams as Rayne blasts its chest flesh
into the air.
Rayne pulls the trigger of her 9mm Beretta, producing a soft click.
[ queued 'load 9mm Beretta' ]
[ Stopped attack. ]
[ queued 'loading a 9mm Beretta' ]
Rayne slips a 9mm clip into her 9mm Beretta.
[s/R][  100%] Rayne steps aside as the shabby monkey goes sprawling.
[R##s][   0%] The shock of Rayne's shot shudders through the shabby monkey.
[ COCK ]: Animal Control -- Rayne earned $55 for a shabby monkey.
Your credit implant beeps for a deposit of $49 from the Animal Control contract.
[ You didn't earn any XP for that. ]
The shabby monkey screeches and jumps up and down wildy in one last final
protest before slumping onto the ground, arms and legs splayed outward.

Yeah that’s me killing a damn monkey. Hell is great. Unfortunately Hell is not always great, here’s me getting killed by some really awesome… something. I’m still not sure if it’s an NPC or not although I’m quite fucking sure it’s an NPC. Yeah I know that last sentence doesn’t make much sense but you know what I mean. It’s Hell for crying out loud!

Velinda exclaims, "Zeenist!"
Velinda attacks you!
Velinda calmly lines up her rusty AK-7 rifle at Rayne.
A red light flashes on the FCPD cam as it swivels toward Velinda.
You start attacking Velinda.
Rayne takes a slice at Velinda with her katana.
n
[ Stopped attack. ]
You try to escape from Velinda!
You couldn't get away!
A K-9 enforcer comes down the street from the north.
s
[ Stopped attack. ]
You try to escape from Velinda!
[ Stopped move. ]
[******************************] [ -30 0/30 ]  So cold...  Your back!
[V###R][  0%] Velinda's rusty AK-7 rifle shot blasts a gaping hole through
Rayne's back!

Sweet death. Unfortunately a rather stupid and maybe unnecessary death but well, I saved my clone so fuck you Hell! Oh and by the wav, wuv you guys!

Posted in English | Tagged , , , , | 3 Comments

Building Checkbox Elements in IE

Why oh why does everything always need to be awkward in IE? Just when you are happily developing in Chrome and/or Firefox and everything is working perfectly you find out that some little bit of javascript or CSS is not working for Internet Explorer. Today we encountered another one of those. This one has to do with dynamically building input elements for a form.

What were trying to do is actually nothing fancy. We just build a few input elements with jQuery and add those to our form:

$(function () {
  $('<input />')
    .attr('value', 'true')
    .attr('name', 'form.IsDefault')
    .attr('type', 'checkbox')
    .appendTo('#testForm');

  $('<input />')
    .attr('name', 'form.Description')
    .attr('type', 'text')
    .appendTo('#testForm');

  $('<input />').
    .attr('type', 'submit')
    .appendTo('#testForm');
});

When we submit the test form, it is send to an action method on our test controller. The method declaration looks like this:

[HttpPost]
public ActionResult Index(TestForm form)
{
    ...
}

The TestForm class is just a representation of our HTML form. It is nothing special:

public class TestForm
{
    public string Description { get; set; }
    public bool IsDefault { get; set; }
}

Everything works beautifully in Chrome and Firefox; when the checkbox is checked and the form is submitted, we can confirm that the value of the IsDefault property on the form parameter is set to true. However, when you run this in IE (confirmed in 8 and 9) the value of the IsDefault property will always be false whether the checkbox is checked or not.

After a few minutes of head scratching and trying some things out, we found out that in the case of IE, the order in which you construct your input attributes (for checkboxes at least) is important.

That means that in IE this does not work as expected:

$('<input />').attr('value', 'true').attr('type', 'checkbox');

But the next bit of code does produce the expected result; note that the order in which the “value” and “type” attributes are set is reversed:

$('<input />').attr('type', 'checkbox').attr('value', 'true');

Also, it doesn’t matter whether you use attr('value', 'true') or val(true). The only thing that is important is that you set the type before the value otherwise you also might end up wondering why your booleans never end up respecting the checkbox state.

Now, I’m not really sure why I am involving jQuery in this because the behavior has nothing to do with jQuery at all. You can easily test it out with the following snippet of code (I’m using a container element here because Firefox doesn’t do outerHTML anymore):

var input = document.createElement('input');
input.setAttribute('value', 'true');
input.setAttribute('type', 'checkbox');

var container = document.createElement('div');
container.appendChild(input);

alert(container.innerHTML);

On my system, both Chrome and Firefox alert <input value="true" type="checkbox" /> but unfortunately IE does not comply and alerts <INPUT type=checkbox>. Apart from the fact that the HTML looks hideous with the unnecessary capitals and lack of double quotes it looks like setting the type attribute in IE may cause the nasty side effect of resetting the “value” attribute back to its default value (which is “on” and is generally useless for everything). And who knows what other attributes get reset by just setting the “type” to a different value?

Posted in English | Tagged , , | 2 Comments