If you need to restrict the characters input into an HTML text form field, use the following Javascript to save time and resources wasted on a round trip to the server.

// Removes all non word characters such as +#</>
frmYourForm.inputText.onkeyup=function(e){
  e=e || window.event;
  var w=e.target || e.srcElement;
  w.value= w.value.replace(/[^\w-]+/g,'');
}

For other patterns check the list on W3Schools.

 

swfupload makes uploading multiple files a snap and look good at the same time. It can be downloaded from Google Code with examples and implementation takes just a few minutes.

Firefox has a problem with the addPostParam call used to add post parameters dynamically. In normal use this is not important but if you wish to pass extra information with the files such as the name of a group to be associated with the files extra work is needed.

It appears only the second and subsequent calls work correctly, yet making two calls right away has no effect, so this won’t work:-

  swfu.addPostParam('groups',params);
  swfu.addPostParam('groups',params);

Firefox also fails if you change the visibility or display settings for container divs and yet these work ok in IE, so if you wish to hide the upload button until another HTML control is completed (such as a location selection filed or group name) you must move the button off the visible area (such as -1000px to the left) and return it afer a valid selection has been made.

How to bully swfupload to work in Firefox

The solution, found for me by my son an hero Adam, was to ignore the documentation and examples that come with it and load the swfu object only when needed and not to use window.onload. I have a function called updgroupval() that is called by the onclick event of a series of checkboxes, the first time this is called the swfu object is loaded:-

function updgroupval(ctl,id) {
	if(ctl.checked) {
		ctl.value = id;
	} else {
		ctl.value = '';
	}
	var params='';
        //a2s converts array into a csv string
	params = a2s(document.form1.group);
	var button = document.getElementById('SWFUpload_0');
	if(params != '') {
		if(swfu) {
			if(button.style.position == "absolute") {
				button.style.position = 'relative';
				button.style.left='0px';
			}
			swfu.addPostParam('groups',params);
		}else{
			settings.post_params.groups = params; 
                        //Create object
			swfu = new SWFUpload(settings);        
		}
	} else {
		button.style.position = 'absolute';
		button.style.left='-100000px';
 
	}	
}

By creating the object after the page has loaded Firefox and the object manage to communicate with addPostParam in the way described in their documentation. Whether this is just a freak of the versions I am using or total nonsense I don’t care. Now I can demonstrate smooth and stylish uploads in Firefox and IE and Chrome, all versions.

 

mypph 300x228 Using twitter as an alerting platformI received an email from Clickatell inviting me to top up my SMS account.  After a split second consideration I realised I did not need them anymore.  Sorry Clickatell!

Twitter is more convenient.  I have set up a few private accounts and subscribed to them through my own.  When an event occurs I receive notification direct to my phone as a free SMS message direct from twitter.

Although twitter has been unreliable lately it has proven more convenient than using Clickatell.  In time twitter will fix the problems and they may even be suitable for mission critical solutions.  I hope so because they are easy to use and should spawn many superb product ideas all designed to keep us informed with the information we want now, not just when we visit facebook.




 

homepage 150x150 Payment Processing for OnelogbookOnelogbook is an outdoor sports activity program currently in development. My task was to add Paypal payment processing to the joining form.

Technologies used were PHP, MySQL, Javascript and I created a few minor graphics. Payment information is sent to Paypal for processing. On successful payment Paypal return IPN (Instant Payment Notification) code to the website and the user is authorised to use the website extended features.

Javascript is used for form validation and PHP provides the server side code. If a payment is cancelled user details are removed from memory and the database is not updated (you can see the cancellation notice at the end of this short high speed video).

And a “Please Wait” graphic – scourge of Paypal Payment Processing!

pleasewait Payment Processing for Onelogbook

 

Styleroomz asked for a widget to showcase products. Data is retrieved from their affiliate source as XML in a zip file.

The XML is updated daily to ensure prices and special offers are fresh.

The widget uses HTML, XML, MySQL, Javascript and PHP. Data sources include XML for the affiliate information such as coded links, pictures, pricing and store information, and MySQL used by the Styleroomz ecommerce software to link to their pages. The Yui library from Yahoo was used to create the carousel effect.

The following short video demonstrates how the widget in use.

 

search results 300x230 Redesigning Styleroomz Product SearchI was given the opportunutiy to alter the search results layout for Styleroomz.com, a fashion website for dress sizes between 16 and 20.  The improved search design required alterations to PHP and Javascript.

 

zoltan 300x256 Lanzaventura Vacation ClubThe site owner needed a new button added which required a small modification to the Javascript and the creation of two images.

 

I just helped with some of the Javascript behind a twitter and Google Mashup called Questioon.

questioon Do you have any Questioons?

Currently available only on the .co.uk but Tunde, the owner, intends to update the .com soon.  Some of the features I added include:

  • A default set of 7 searches on the front page (called quick links)
  • Default searches replaces with the last 7 searches you made
  • Ability to delete an individual search
  • Ability to reset all quick links
  • Used Juitter to embed twitter feed on the results page

The design was created by another developer.

 

To remove stuff such as punction and spaces (or anything you want) from a text box before sending to the server for validation you can use code like this, first the HTML:-

<input
name="name"
onblur="this.value = entrycheck(this.value);"
type="text"
size="20">

And then the following Javascript will remove invalid characters when the user moves to another field:-

<script type="text/javascript">
function namecheck(theInput) {
  var valid = 'abcdefghijklmnopqrstuvwxyz1234567890';
  var test ='';
  var ret ='';
  for(i=0;i<theInput.length;i++) {
    test = theInput.substr(i,1);
    if(valid.indexOf(test.toLowerCase()) != -1) {
      ret = ret + test;
    }
  }
  return ret;
}
</script>

In this example I just want digits and characters. If you want to add certain punctuation such as stops and commas just add them to the valid variable.

© 2011 Martyn Walker | Software Architect | Hiker And Hacker Suffusion theme by Sayontan Sinha