Archive for the “Javascript” Category

Ever wanted a getJSON which does a post?

Here it is:

jQuery.extend({
    postJSON: function(url, data, callback)
    {
        $.post(url, data, callback, "json");
    }
});

Comments No Comments »

Suppose you have a button named "submit":

<form method="post" action="" id="myForm">
    <fieldset>
        <input type="text" name="myField" />
        <input type="submit" name="submit" value="submit form" />
    </fieldset>
</form>

And you want to submit this form with jQuery:

<script type="text/javascript">
    SomeFunction()
    {
        $("#myForm").submit();
    }
</script>

That won’t work since you have a button named ‘submit’ which then screws up the jQuery function. If you rename it to ‘submitForm’ or something it will work fine.

Comments No Comments »

Die er niet is :P

Er is dus geen foreach in Javascript. Jammer want dit geeft meer obvious code:

String[] listNames = listViewNames.GetNames();

for(int x = 0; x < listNames.length; x++)
{
	String name = listNames[i];
	//do something with name
}

wordt...

String[] listNames = listViewNames.GetNames();

foreach(String name in listNames)
{
	//do something with name
}

Er is wel een andere syntax voor het for statement, wat lijkt op foreach

var listnames = listViewNames.GetNames();

for(var index in listNames)
{
	//i is now the index
	var name = listNames[index];
	//do something with name
}

Een extra stap dus, maar het kan handig zijn

Comments No Comments »

And shepherds we shall be, for thee my Lord for thee, power hath descended forth from thy hand, that our feet may swiftly carry out thy command. We shall flow a river forth to thee, and teeming with souls shall it ever be. In nomine Patris, et Filii, et Spiritus Sancti.