31 Jan 2014

How to get the Value of a Textfield after clicking on a Button (JQuery)

1. Include JQuery to your HTML File:

We need the code above to be able to use JavaScript.


2. Create a Textfield:

 





It will look like this:


 

3. Create a Button:





It will look like this:


 

4. Create the JQuery function:

 













As you can see we have to code our function between 'script' tags.
We should always use $(document).ready before other functions to prevent loading errors because this event does not get triggered until all assets such as images have been completely received.


$("#button").click: Let's write the ID of the Button between the brackets and use the .click function. So the function will start after clicking the button with the ID "button".

var value = document.getElementById("textfieldid").value:
We declare the variable value and fill it with the value of the textfield we created above. We could also use .getElementByName(). but we had to replace "textfieldid" with "textfieldname" then. (see 2. Task)

alert(value):  The alert opens the pop up with the text we typed in.

5. Test  

 

Open the file wth you browser!


It will look like this:



If we click on the button this pop up will appear:











29 Jan 2014

Fill data from Database to Listbox (PHP)

What you need:
Database connection

 1. Save your Select into a variable

 


With this Select we can get all (*) the data from the database table called "Nations". I saved the Query into a variable called $sql.


1.1 Send your Query and check if it was successful

 

mysql_query($sql) sends a request to the Server with the Select variable we created above. Add "or die" to check if we get any errors. The request will be automatically canceled and the message inside the brackets of die( ) will be saved into $result. If the query is successful we will get all the data from "Nations" as mentioned above.


2. Creat the head of the Listbox

 




If you set no size it will become a drop down list.

3. Get the first row of $result






Since $result can has more than one Nation in it, we have to read each row separated to get every single Nation out of it. With mysql_fetch_assoc() this is possible.


4. Fill data from Database to Listbox

 

 

 

 


As you can see we have to use a while loop until our condition is false. We write every Nation's name to the Listbox between the 'option' tags and get the next Nation with mysql_fetch_assoc(). When our $nation is empty it will automatically leave the while loop and close the Listbox. 

28 Jan 2014

Database connection with PHP (MySQL)


What you need:
  • servername (e.g. localhost)
  • username
  • password
  • databasename

 

1. Fill mysql_connect() with the database information above:

 

1.1 Fill mysql_select_db() with the database name:

 

1.2 Declare 2 variables for both methods above:

We need these variables for checking errors.

 

2. Checking Errors:

 

2.1 Check if the connection was successful:

 

The method mysql_error() displays the connection error. You should always use this to see what you did wrong. 

 

2.2 Check if the selected database exists:

 

3. Success


Your browser will show you this if you did everything right:

Clickable Text for Radio Buttons (HTML)

1. Creating the Radio Button with the code below: 

 

1.1 How it looks like: 

 

Test

If you click on the Text nothing happens.

2. Making the Text clickable: 

 

 You just have to add the tag:


So the final version will look like this:

2.1 How it looks like:

 

If you click on the Text the Radio Button will be checked.


3. Information

 

You should always use the tag for Accessibility. It will make your Website user-friendly.