xtra tips

download xtra tips

of 2

Transcript of xtra tips

  • 8/6/2019 xtra tips

    1/2

    -To add a tab in HTML use &nbsp (non-breaking space).

    -To clear a textbox on focus use:

    -If you use a class id for a link and want to add mouse over effects through CSSdo as follows:

    a.hlink:hover{text-decoration:none;}

    where hlink is the name of the class.

    -To make a group of radio boxes, make sure that their name attributes have the same value.

    -To check whether a radio box is checked or not, use if(form.name[0].checked==true) statement. All radio buttons with the same name (same group) are stored as a

    n array that's why we've used name[0] here to check the first radio button's check condition. Similarly we can check for other radio buttons too by just incrementing the array index.

    -To check whether a number is entered or not, we can use isNaN(form.field.value)function which returns true if value is not a number.

    -To turn on error reporting in php follow the steps here http://www.ibm.com/developerworks/library/os-debug/

    -To check for logins using PHP, first use a query likeSELECT user, pass FROM login WHERE user='$username' AND pass='$password'and then apply the function mysql_num_rows($result) to check that only 1 row isreturnded.

    -Storing an array in database:Let's say that you've got a form with check boxes sort of like:

    Red Blue Green Yellow

    You want to store the information in that array to your database.$colors=serialize($_POST['colors']); //takes the data from a post operation...$query=INSERT INTO colors VALUES('$colors');

    To retrieve the array data from the database, then, you might do this:

    $colors=unserialize($colors['colors']);

    -Running a php script on the same page (without refresh):PHP is a server side technology but sometimes you may need to run php operations

    on the client side using a combination of JavaScript & PHP on the same page. This can be done by explicitly passing variables from JavaScript to PHP by using window.location.href functionality.

  • 8/6/2019 xtra tips

    2/2

    One of the frequent problems is defining visitor s screen resolution using JavaScript tools and passing this data to PHP-script.

    width = screen.width;height = screen.height;if (width > 0 && height >0) {

    window.location.href = "http://localhost/main.php?width=" + width + "&height=" + height;} else

    exit();

    Main.php looks like this:

    As you can see, passing JavaScript variables in PHP is similar to sending data using GET method.