Youtube embed code to pass w3c HTML validation? yes there’s a solution, see here!

July 17th, 2010

For those who scour the net for a simple solution for a problem called “Make my YouTube embed code pass w3c HTML validation“, your in the PERFECT place, because what you’re about to read is not only simple, but the perfect solution!

Very confident me will now show you how its done :)

The usual Youtube embed code(do not pass w3c HTML validation)
NOTE: where ($vid) is your Youtube video ID

<object width="430" height="347">
<param name="movie" value="http://www.youtube.com/v/($vid)&amp;hl=en_US&amp;fs=1"></param><param name="allowFullScreen" value="true"></param><param name="allowscriptaccess" value="always"></param>
<embed src="http://www.youtube.com/v/($vid)&amp;hl=en_US&amp;fs=1" type="application/x-shockwave-flash" allowscriptaccess="always" allowfullscreen="true" width="430" height="347"></embed>
</object>

Ok you see, when using this code to display video, it will never pass validation but instead will render validation error such as “there is no attribute allowfullscreen”, “width” among others.

But with the code below, you can perfectly validate your Youtube pages :) see below and test it yourself.

NOTE: ($vid) is = to your Youtube video ID, for example http://www.youtube.com/v/RHzC7YOxkVY&hl=en_US&fs=1 the emphasized letters is your Youtube ID, So now presenting the code…

<object type="application/x-shockwave-flash" width="430" height="347" data="http://www.youtube.com/v/($vid)">
<param name="movie" value="http://www.youtube.com/v/($vid)" /></object>

Oh my, yes its much shorter, and its better!!! :D

Javascript concatenates instead of adding two form values? There’s an easy solution: parseInt() Javascript function

July 1st, 2010

Javascript concatenates instead of adding two form values?

Ok, lets test this :)

SEE DEMO

<form id="form2" name="form2" method="post" action="#" onsubmit="document.getElementById('total2').value=parseInt(document.getElementById('field12').value)+parseInt(document.getElementById('field22').value); return false;">
  <p>
    <input type="text" name="field12" id="field12" />
  </p>
  <p>
    <input type="text" name="field22" id="field22" />
  </p>
  <p>
    <input type="submit" name="button" id="button" value="Add" />
  = 
  <input name="total2" type="text" id="total2" size="10" />
  </p>
</form>

True enough treat form values as string, so concatenates.

So, what should we do to make Javascript add those form values?

We can use Javascript function called parseInt().

The parseInt() function parses a string and returns an integer.

Ex: form.field2.value+form.field2.value (this will only concatenate)

SEE DEMO

<form id="form2" name="form2" method="post" action="#" onsubmit="document.getElementById('total2').value=parseInt(document.getElementById('field12').value)+parseInt(document.getElementById('field22').value); return false;">
  <p>
    <input type="text" name="field12" id="field12" />
  </p>
  <p>
    <input type="text" name="field22" id="field22" />
  </p>
  <p>
    <input type="submit" name="button" id="button" value="Add" />
  = 
  <input name="total2" type="text" id="total2" size="10" />
  </p>
</form>

Thats it! that should add two form values perfectly :) feel free to post any question and or comments thanks.

How to customize Magento’s currency symbol?

June 22nd, 2010

Editing Magento’s default currency symbol is relatively easy and can be done via admin.

But what if you wanted to display “USD” instead of “$”?

This too is easy enough for most of us-if you know where to look at! :)

Ok ok, to edit or customize default currency symbol look into;

MAGENTO_ROOT/lib/Zend/Locale/Data/

Look for you locale, in most cases en.xml (which is english), download and open it in your favorite editor, replace below code

<currency type="USD">
    <displayName>US Dollar</displayName>
    <displayName count="one">US dollar</displayName>
    <displayName count="other">US dollars</displayName>
    <symbol>$</symbol>
</currency>

With this code:

<currency type="USD">
    <displayName>US Dollar</displayName>
    <displayName count="one">US dollar</displayName>
    <displayName count="other">US dollars</displayName>
    <symbol>USD</symbol>
</currency>

I think you already noticed what we omit and replace on the code :) , easy enough, saved it and upload it to your server.

To make your life even more easier here’s a tip: you can find this line of code around line 3800 in en.xml

GOGOGO :)

Validating textfield to accept numbers and letters only, via Javascript

May 31st, 2010

Sometimes we wanted to validate user inputs, and more often than not we want to restrict then to only accept letters, numbers and spaces for a specific form field.

Today Ill show you how to do this via Javascript.

The below codes will demonstrate this for your quick understanding:

<form id="form1" name="form1" onsubmit="if(/[^A-Za-z\d ]/.test(this.textfield.value)){alert('String should contain letters and numbers only');}else{alert('String passed');}" method="post" action="">
  <input type="text" name="textfield" id="textfield" value="Input text here." onclick="this.value=''" />
  <input type="submit" name="button" id="button" value="Submit" />
</form>

On submit event Javascript will test value of the textfield using “/[^A-Za-z\d ]/“, if any character is found other than letter, number and space it will return TRUE and alert us that it contains illegal character(s) (letter, number and space).

Please see demo

Easy huh, try it yourself. :)