Monthly Archives: December 2011

CSS Trick: Resize background image to fit browser window

Here is the neat little block of CSS that I use to resize a background image to fit the size of the browser window the site is being viewed in:

body {
        background: url(images/bg.jpg) no-repeat center center fixed;
        -webkit-background-size: cover;
        -moz-background-size: cover;
        -o-background-size: cover;
        background-size: cover;
}

Let me know if you have any questions or need help with this! :)

Website forms: Use Javascript to auto fill one field with the values from two other fields

Here is the simple Javascript code that I use to auto fill one field of a form with the values of one or more other fields.

Copy and paste this line to the <head> of your web page:

 

<script type="text/javascript" charset="utf-8">    
function updateUsername(){        
first = document.getElementById("first").value;        
last = document.getElementById("last").value;         document.getElementById("username").value = first+" "+last;    
} </script>

 

Next, you simply need to add the correct ID to the three fields in your form. Make sure that the IDs correspond correctly to the Javascript code we just pasted into the header.

For example:

<input type="text" name="some_name" value="" id="first" onkeyup="updateUsername();">
<input type="text" name="some_name" value="" id="last" onkeyup="updateUsername();">
<input type="text" name="some_name" value="" id="username">

As you can see, you also need to add this line of code to the field or fields whose value(s) you want to fill the third field:

onkeyup="updateUsername();"

And that is all that you need to do. Let me know if you have any questions or run into any issues.

Fixing the “Warning: array_merge() [function.array-merge]:” error in WordPress’s WP-Ecommerce plugin

When I first installed the WP-Ecommerce plugin on a website this morning and tried to go to the products page, I got this error:

Warning: array_merge() [function.array-merge]: Argument #1 is not an array in /public_html/wp-content/plugins/wp-e-commerce/wpsc-core/wpsc-functions.php on line 622

Thankfully, it is actually very easy to fix this error. All you need to do is add (array) to the correct line of code in the plugin’s functions.php file.

Find this line in your wp-e-commerce/wpsc-core/wpsc-functions.php file:

$args = array_merge($wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));

And change it to this:

$args = array_merge((array)$wp_query->query, array('posts_per_page' => get_option('wpsc_products_per_page')));

 

That did the trick for me and hopefully will work for you too. Let me know if you have any questions or run into issues with this.