ELATED: Authoring and Programming http://www.elated.com/ The nitty-gritty of coding websites. Get help with HTML, CSS, JavaScript, PHP, Perl, or any other Web programming problem. en-us Wed, 26 Jul 2017 18:46:18 GMT Wed, 26 Jul 2017 18:46:18 GMT http://blogs.law.harvard.edu/tech/rss ELATED.com feeder Re: Banner rate http://www.elated.com/forums/topic/6345/#post26732 From: chrishirst


No idea to both questions, because it depends ENTIRELY on the marketplace and whether the visitors are 'qualified', which means, are they actually going to be USEFUL to the advertiser(s).

C.P.M. means "Cost Per Mille", mille being 1000. So C.P.M. equates to "cost per thousand impressions".

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 21 Jul 2017 13:39:22 GMT http://www.elated.com/forums/topic/6345#post26732
Banner rate http://www.elated.com/forums/topic/6345/#post26731 From: brucebrown


Assuming that my web site is getting about 150,000 impressions per month, how much should I charge for a banner ad? If I'm getting less impressions, how much would I charge?

What is a cpm?

View » | Reply »

]]>
Fri, 21 Jul 2017 12:15:59 GMT http://www.elated.com/forums/topic/6345#post26731
Re: Javascript help adding if statement http://www.elated.com/forums/topic/6344/#post26730 From: chrishirst


You cannot do this;


Code:
--------------------
lInputs[i].checked = false;
--------------------


An unchecked box is not 'false', it will return 'undefined' or 'null' as only a checked box will return a value of true.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 21 Jul 2017 02:53:31 GMT http://www.elated.com/forums/topic/6344#post26730
Re: Build a CMS in an Afternoon with PHP and MySQL http://www.elated.com/forums/topic/5114/#post26729 From: prakul


Hi Matt,
First I was impressed your answered. You just not answered like others, but give them the working code.!!

I tried to add Search for Topic or Category by add form at the head. But somehow not success.
All detail I post in github here :https://github.com/kul1/elated

Here the code:
1. ./templates/include/search.php

Code:
--------------------
<html>
<form action="?action=searchTitle" method="post">
<input type="text" name="mytitle" />
<input type="submit" name = submit value="Search Title" />
</form>
</html>

--------------------


2. Add case searchTitle and function searchtitle()


Code:
--------------------
<?php

require( "config.php" );
include "templates/include/search.php";



$action = isset( $_GET['action'] ) ? $_GET['action'] : "";

switch ( $action ) {
case 'archive':
archive();
break;
case 'viewArticle':
viewArticle();
break;
case 'searchTitle':
searchtitle();
break;
default:
homepage();
}

function archive() {
$results = array();
$categoryId = ( isset( $_GET['categoryId'] ) && $_GET['categoryId'] ) ? (int)$_GET['categoryId'] : null;
$results['category'] = Category::getById( $categoryId );
$data = Article::getList( 100000, $results['category'] ? $results['category']->id : null );
$results['articles'] = $data['results'];
$results['totalRows'] = $data['totalRows'];
$data = Category::getList();
$results['categories'] = array();
foreach ( $data['results'] as $category ) $results['categories'][$category->id] = $category;
$results['pageHeading'] = $results['category'] ? $results['category']->name : "Article Archive";
$results['pageTitle'] = $results['pageHeading'] . " | Widget News";
require( TEMPLATE_PATH . "/archive.php" );
}

function viewArticle() {
if ( !isset($_GET["articleId"]) || !$_GET["articleId"] ) {

homepage();
return;
}

$results = array();
$results['article'] = Article::getById( (int)$_GET["articleId"] );
$results['category'] = Category::getById( $results['article']->categoryId );
$results['pageTitle'] = $results['article']->title . " | Widget News";
require( TEMPLATE_PATH . "/viewArticle.php" );
}

function homepage() {
$results = array();
$data = Article::getList( HOMEPAGE_NUM_ARTICLES );
$results['articles'] = $data['results'];
$results['totalRows'] = $data['totalRows'];
$data = Category::getList();
$results['categories'] = array();
foreach ( $data['results'] as $category ) $results['categories'][$category->id] = $category;
$results['pageTitle'] = "Widget News";
require( TEMPLATE_PATH . "/homepage.php" );
}

function searchtitle() {

//if ( !isset($searchitem) || !$searchitem) {
if ( !isset($_POST["mytitle"]) || !$_POST["mytitle"] ) {
homepage();
return;
}
echo "<br/>";
$searchitem = $_POST["mytitle"];

echo '$searchitem in side searchtitle = >>>>>>>>>> '.$searchitem;

$results = array();
$results['article'] = Article::getByTitle($searchitem);

echo "<br/> ";
print_r($results['article']);

echo "<br/> Here I have problem with the next line results['category'] is not work";

$results['category'] = Category::getById($results['article']->categoryId);
//$results['pageTitle'] = $results['article']->title . " | Widget News";
//require( TEMPLATE_PATH . "/viewArticle.php" );
//$results['pageHeading'] = $results['category'] ? $results['category']->name : "Article Archive";
//$results['pageTitle'] = $results['pageHeading'] . " | Widget News";
//require( TEMPLATE_PATH . "/archive.php" );

homepage();
return;
}
?>

--------------------


3. Modify classes/Article.php
Add function getByTitle


Code:
--------------------

public static function getByTitle( $mytitle=null, $numRows=1000000, $categoryId=null, $order="publicationDate DESC" ) {
echo "<br/>";
echo 'getByTitle = >>>>>>>>>> '.$mytitle;


$conn = new PDO( DB_DSN, DB_USERNAME, DB_PASSWORD );
$categoryClause = "WHERE title = ".$mytitle;

echo "<br/>";
echo 'DB_DSN, DB_USERNAME, DB_PASSWORD = >>>>>>>>>> '.DB_DSN.",".DB_USERNAME.".".DB_PASSWORD;

echo "<br/>";
echo '$categoryClause = >>>>>>>>>> '.$categoryClause;

//$sql = "SELECT SQL_CALC_FOUND_ROWS *, UNIX_TIMESTAMP(publicationDate) AS publicationDate FROM articles $categoryClause ORDER BY " . ($order) . " LIMIT :numRows";
$sql = "SELECT SQL_CALC_FOUND_ROWS * FROM articles WHERE title = 'Forth Title'";

$st = $conn->prepare( $sql );
$st->bindValue( ":numRows", $numRows, PDO::PARAM_INT );
if ( $categoryId ) $st->bindValue( ":categoryId", $categoryId, PDO::PARAM_INT );
$st->execute();
$list = array();

echo "<br/>";
print_r($list);

while ( $row = $st->fetch() ) {
$article = new Article( $row );
$list[] = $article;
}

// Now get the total number of articles that matched the criteria
$sql = "SELECT FOUND_ROWS() AS totalRows";
$totalRows = $conn->query( $sql )->fetch();

echo "<br/>";
echo "---------->".$totalRows[0];

$conn = null;
return ( array ( "results" => $list, "totalRows" => $totalRows[0] ) );
}

--------------------



Somehow the function searchtitle() have problem


Code:
--------------------
Notice: Trying to get property of non-object
--------------------



Perhaps there is any other better way to search Title or Category(not here yet). Or how to fix it.

Thanks
Peter

--
Peter Cooling

View » | Reply »

]]>
Thu, 20 Jul 2017 19:55:45 GMT http://www.elated.com/forums/topic/5114#post26729
Javascript help adding if statement http://www.elated.com/forums/topic/6344/#post26728 From: esowers


Hey,

I'm running into trouble adding an if statement around some pre-existing javascript that I have. Essentially I have a checkbox field within my webpage that may be in an array, or it may be a straight variable, depends on how many different options there are. (ie if the page loads and there's only one option, then the checkbox will be a variable with no array, else with two or more options it will be in an array with the same tagname).



Code:
--------------------
<!-- Script to control the function of the check boxes -->
<script>
var inputs;
$( document ).ready(function() {
inputs = document.getElementsByTagName("input");
if(inputs.constructor === Array){
for(var i = 0; i < inputs.length; i++) {
if(inputs[i].type == "checkbox") {
inputs[i].onclick = function() { checkOnly( this.name ); };
}
} else{

}
}

}

});

function checkOnly(stayChecked) {
var lInputs = document.getElementsByTagName("input");
var fieldNum = 0;
for(var i = 0; i < lInputs.length; i++) {
if(lInputs[i].type == "checkbox") {
if ( stayChecked != lInputs[i].name ) {
lInputs[i].checked = false;
} else {
//Set the selected cost for this registration
var selectedCost = document.getElementById( "tfa_2201[" + fieldNum + "]");
var setSelectedCost = document.getElementById( "tfa_2202" );
setSelectedCost.value = selectedCost.value;
//Set the selected price for this registration
var selectedPrice = document.getElementById( "tfa_2197[" + fieldNum + "]" );
var setSelectedPrice = document.getElementById( "tfa_2204");
setSelectedPrice.value = selectedPrice.value;
//Set the amount due field
var selectedPrice = document.getElementById( "tfa_2197[" + fieldNum + "]" );
var setSelectedPrice = document.getElementById( "tfa_2532");
setSelectedPrice.value = selectedPrice.value;
}
fieldNum++;

}
}

}

</script>
--------------------


If someone could help us add an if statement to this it would be super helpful. The function is that when a checkbox is checked it will take one fields value and populate it in another field.

View » | Reply »

]]>
Thu, 20 Jul 2017 19:13:05 GMT http://www.elated.com/forums/topic/6344#post26728
Re: PHP Data Types http://www.elated.com/forums/topic/4724/#post26726 From: chrishirst


Objects are [b]NOT really[b] data 'types' which is why they are not covered as simple data 'types'

'Objects' are an abstract structure of variables which are containers of scalar data types, arranged as an associative array

PLUS;

" but it is not mentioned in this article."

Had you actually read the article all the way through you would have found arrays and objects covered in the section headed with

"PHP's compound data types"

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Mon, 17 Jul 2017 10:24:36 GMT http://www.elated.com/forums/topic/4724#post26726
Re: PHP Data Types http://www.elated.com/forums/topic/4724/#post26725 From: olidev


Objects are also a type of data in PHP, but it is not mentioned in this article. Arrays and function are some examples of an Object. Here is how a new Object is created.

$car = new ferrari();

Source: https://www.cloudways.com/blog/php-data-types-and-variable-concepts/

View » | Reply »

]]>
Mon, 17 Jul 2017 07:18:40 GMT http://www.elated.com/forums/topic/4724#post26725
Managing callback in argument in javascirpt http://www.elated.com/forums/topic/6343/#post26723 From: zesanriky


The async function itself should make use of the lookup() function but return the result inside the callback.

The parameters for the callback are err and res.

If an Error has been thrown by lookup() then it should be passed to err, otherwise err is null or undefined.If a result has been returned by lookup() then it should be passed to res, otherwise res is null or undefined.



<!DOCTYPE html>
<html>
<body>
<script src="https://wzrd.in/standalone/tape@latest"></script>
<script src="https://wzrd.in/standalone/tap-browser-color@latest">
</script>
<script src="https://wzrd.in/standalone/deep-freeze@latest"></script>
<script>
window.test = tape;
tapBrowserColor();
</script>
</body>
</html>

<script>

const users = [
{
"login": "knuth",
"firstName": "Donald",
"lastName": "Knuth",
"likes": ["C", "Unix"]
},
{
"login": "norvig",
"firstName": "Peter",
"lastName": "Norvig",
"likes": ["AI", "Search", "NASA", "Mars"]
},
{
"login": "mfowler",
"firstName": "Martin",
"lastName": "Fowler",
"likes": ["Design Patterns", "Refactoring"]
},
{
"login": "kent",
"firstName": "Kent",
"lastName": "Beck",
"likes": ["TDD", "wikis", "Design Patterns"]
}
];

// lookup()
const lookup = (login, prop) => {
// Only change code below this line
const found = users.find(function(e){
return e.login === login;
});
if(!found) {
throw "Could not find user";
} else {
if(prop in found) {
return found[prop];
} else {
throw "Could not find property";
}
}
};

// lookupAsync()
const lookupAsync = (login, prop, callback) => {
// Only change code below this line
const found = users.find(function(e){
return e.login === login;
});
if(!found) {
throw "Could not find user";
} else {
if(prop in found) {
return found[prop];
} else {
throw "Could not find property";
}
}

//my intension below but doesn't work
//callback();
//lookupAsync(function (err,res) {});

};
test('lookupAsync() likes', assert => {
const msg = `lookupAsync(<login>, 'likes', callback) should return

likes

for the specified user.`;

lookupAsync('norvig', 'likes', function(err, res){
const actual = res;
const expected = ["AI", "Search", "NASA", "Mars"];
assert.deepEqual(actual, expected, msg);
assert.end();
});

});


test('lookupAsync() last name', assert => {
const msg = `lookupAsync(<login>, 'lastName') should return the last

name
for the specified user.`;

lookupAsync('knuth', 'lastName', function(err, res){
const expected = 'Knuth';
const actual = res;
assert.deepEqual(actual, expected, msg);
assert.end();
});
});


test('lookupAsync() with unknown user', assert => {
const msg = `lookupAsync() with unknown user should return an error
with the correct message.`;

const value = lookupAsync('nobody', 'likes', function(err, res){
const actual = err.message;
const expected = 'Could not find user.';
assert.equal(actual, expected, msg);
assert.end();
});
});


test('lookupAsync() with unknown property', assert => {
const msg = `lookupAsync() with unknown property should return an

error
with the correct message`;

lookupAsync('mfowler', 'noprop', function(err, res){
const actual = err.message;
const expected = 'Could not find property.';
assert.equal(actual, expected, msg);
assert.end();
});
});


</script>

The output should look like(short from) :

1..4
# tests 4
# pass 4
# ok

[Edited by zesanriky on 16-Jul-17 15:38]

View » | Reply »

]]>
Sun, 16 Jul 2017 20:36:27 GMT http://www.elated.com/forums/topic/6343#post26723
Re: html-stylesheet linkage http://www.elated.com/forums/topic/6341/#post26720 From: chrishirst



Code:
--------------------
<link rel="stylesheet" type="text/css" href="path_to_css_file.css">
--------------------



https://www.w3schools.com/tags/tag_link.asp

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 14 Jul 2017 18:50:56 GMT http://www.elated.com/forums/topic/6341#post26720
html-stylesheet linkage http://www.elated.com/forums/topic/6341/#post26718 From: newbie1022


I am having trouble getting the html sheet I have created to reference its stylesheet, a separate CSS file, in the same folder. What are the critical parts that make this happen? I have seen two instructors do this, but I cannot make it happen.

--
Jim Williams

View » | Reply »

]]>
Thu, 13 Jul 2017 21:54:16 GMT http://www.elated.com/forums/topic/6341#post26718
Re: Where http://www.elated.com/forums/topic/6340/#post26717 From: chrishirst


You're not a Douglas Adams aficionado I guess,


It is what was etched into the goldfish bowl that the Dolphins left for Arthur Dent on his return to Earth, and was the final message to Earth from the dolphins.

Also the Quandary Phase of the Hitchhikers Guide to the Galaxy. https://www.youtube.com/watch?v=Gi08277caUQ

(The books and radio/TV Series are much better than the film)

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Wed, 12 Jul 2017 22:46:09 GMT http://www.elated.com/forums/topic/6340#post26717
Re: Where http://www.elated.com/forums/topic/6340/#post26716 From: newbie1022


Ok, thanks! That's a little easier to understand, I think.
AND, where are you getting "all the fish" from?

--
Jim Williams

View » | Reply »

]]>
Wed, 12 Jul 2017 18:54:51 GMT http://www.elated.com/forums/topic/6340#post26716
Re: Where http://www.elated.com/forums/topic/6340/#post26715 From: chrishirst


Classes and IDs are styling components NOT structural elements, so they do NOT 'distinguish' elements structurally, they CAN be used to distinguish elements visually, but that is not necessarily the case as a class AND an ID may be styled identically

'div' is short for 'a division' element, so non-visual user agents can determine that the content of that particular element is separated from the preceding and following content, while not giving the content any particular significance.

A paragraph '<p>' does the same thing in separating content, BUT also gives the content some significance, just as a paragraph break would do on a printed page.

"WHERE do divs fit in the parent/child relationships between the body and other parts?

There is no particular "parent - child relationship", you as the developer define what the element hierarchy will be.
There are just the standard 'rules' of HTML. Which are:
Divs are a block level element so can be a child of other block level elements or a parent of block level and/or inline level elements. Whereas inline level elements can be parent ONLY to other inline elements

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Wed, 12 Jul 2017 18:31:55 GMT http://www.elated.com/forums/topic/6340#post26715
Where http://www.elated.com/forums/topic/6340/#post26714 From: newbie1022


I am having a hard time seeing the point of the div element. If you have classes, ID's and other means of distinguishing paragraphs and other elements, what's the point of div's? And WHERE do divs fit in the parent/child relationships between the body and other parts?

--
Jim Williams

View » | Reply »

]]>
Wed, 12 Jul 2017 14:43:23 GMT http://www.elated.com/forums/topic/6340#post26714
Re: Fading Nav Bar http://www.elated.com/forums/topic/6339/#post26713 From: chrishirst


"as I scroll up it snaps back instead of fading back out. "

As it will, given that you remove the very thing that makes it 'fade'.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Sun, 09 Jul 2017 10:12:07 GMT http://www.elated.com/forums/topic/6339#post26713
Fading Nav Bar http://www.elated.com/forums/topic/6339/#post26712 From: neotrad


I need help with coding the nav bar, I can get it to fade into the new color when scrolling down, but as soon as I scroll up it snaps back instead of fading back out.

html:


Code:
--------------------

<div>
<nav class="nav">
<ul class="menu">
<li><a href="#">Home</a></li>
<li><a href="#">About</a></li>
<li><a href="#">Portfolio</a></li>
<li><a href="#">Blog</a></li>
</ul>
</nav>
</div>
--------------------



css:



Code:
--------------------
.changeColor {
background: #d13e3f;
transition: 1.5s all;
}
--------------------



javascript:



Code:
--------------------
$(window).scroll(function(){
if ($(this).scrollTop()>1000){
$('.menu').addClass("changeColor");
}
else
{
$('.menu').removeClass("changeColor");
}
})
--------------------


--
Ruan Jordaan

View » | Reply »

]]>
Sat, 08 Jul 2017 22:49:49 GMT http://www.elated.com/forums/topic/6339#post26712
Re: stuck left justified! http://www.elated.com/forums/topic/6338/#post26711 From: chrishirst


Oh and HTML/CSS it will be 'left aligned', 'justify' is related to text flow.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 07 Jul 2017 20:52:05 GMT http://www.elated.com/forums/topic/6338#post26711
Re: stuck left justified! http://www.elated.com/forums/topic/6338/#post26710 From: chrishirst


"Headers and paragraphs appear stuck on the left side."

That's the norm for the HTML document flow.

"Do you have to box em on the screen to move em?"

Haven't a clue what you mean by this. 'em' is a dimensional unit for layout positions and font sizes.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 07 Jul 2017 20:50:06 GMT http://www.elated.com/forums/topic/6338#post26710
stuck left justified! http://www.elated.com/forums/topic/6338/#post26709 From: newbie1022


Headers and paragraphs appear stuck on the left side. I managed to put one in a block and move it over with a large left margin, but I couldn't move the first or second headers off the left margin, even with a large margin number in the style box. Do you have to box em on the screen to move em?

--
Jim Williams

View » | Reply »

]]>
Thu, 06 Jul 2017 23:50:13 GMT http://www.elated.com/forums/topic/6338#post26709
Re: what's the difference? http://www.elated.com/forums/topic/6337/#post26707 From: chrishirst


<br> is for HTML code.

<br/> is for XHTML code.


The difference is that XHTML requires all 'tags' to be closed and as <br> is a single tag that has no equivalent 'close' tag, the '/>' makes it 'self-closing'

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Wed, 05 Jul 2017 10:08:43 GMT http://www.elated.com/forums/topic/6337#post26707
what's the difference? http://www.elated.com/forums/topic/6337/#post26705 From: newbie1022


Between <br> and <br/>? I have seen a few other tags with the / after the letters. What's the purpose of it being after the letters?

--
Jim Williams

View » | Reply »

]]>
Tue, 04 Jul 2017 22:47:50 GMT http://www.elated.com/forums/topic/6337#post26705
Re: JavaScript Tabs - Create Tabbed Web Pages Easily http://www.elated.com/forums/topic/4717/#post26702 From: anhr


I took the ideas from this article and wrote my own code. Please see my cross-browser JavaScript code: https://github.com/anhr/Tabs.

You can use different ways to create tabs and tab content.

Tab content can added only when tab gets focus.

You can remember selected tab. Selected tab opens immediatelly after opening of the page.

You can create tabs inside tab.

Custom background of the tab is available.

Example: http://anhr.ucoz.net/Tabs/

--
Andrej web developer

View » | Reply »

]]>
Sun, 02 Jul 2017 13:02:23 GMT http://www.elated.com/forums/topic/4717#post26702
Re: How can I update mySQL Database using PHP & HTML Form http://www.elated.com/forums/topic/6335/#post26699 From: chrishirst


" But it adds a new row under the username column in the database"

Which is exactly what an INSERT query will do.

Changing data requires an UPDATE query https://www.w3schools.com/php/php_mysql_update.asp

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 30 Jun 2017 12:24:32 GMT http://www.elated.com/forums/topic/6335#post26699
How can I update mySQL Database using PHP & HTML Form http://www.elated.com/forums/topic/6335/#post26698 From: VenoM


Greetings,
So before I dive into my problem, I'll explain what I'm trying to achieve. I'm making a profile page. I already have a login system which means I have stored the user's email, password, first name, last name in my database. Now to improve my profile page, I'm trying to also add a username, city & country blank The user will be able to set a username when he visits the profile page. Before that, the username blank in the database is empty. Now I tried to implement the INSERT method to my username form blank. But it adds a new row under the username column in the database. This is the example: http://imgur.com/pl1Aywd

My problem is similar to this: https://stackoverflow.com/questions/21994209/updating-a-user-profile-stored-in-session-data-from-an-sql-database-with-ajax

I want the username to appear in the logged in user's row e.g my account name is Hamza Ch so the username I set (pointz0r) should be in my row and not make a new row.

This is my HTML form: https://codeshare.io/5wyNbK

I have an action.php but It's really messed up. I was hoping someone can direct me to a blog post or a tutorial where I can find the solution. Or help me with the solution himself. I'm just a beginner in PHP and I really want to get this done at this once. Thanks in advance!

View » | Reply »

]]>
Fri, 30 Jun 2017 11:16:34 GMT http://www.elated.com/forums/topic/6335#post26698
Re: jQuery Mobile: What Can It Do for You? http://www.elated.com/forums/topic/5050/#post26697 From: cohenarik18


I have the same problem on this site http://seo-google.co.il/. Does anyone have an idea?

--
seo-google

View » | Reply »

]]>
Thu, 29 Jun 2017 11:30:18 GMT http://www.elated.com/forums/topic/5050#post26697
HTML + PHP + Mysql help http://www.elated.com/forums/topic/6334/#post26692 From: Samuel Hulme


http://www.elated.com/forums/topic/6333/

is what is what i need help on

--
http://minersonl.mypressonline.com

View » | Reply »

]]>
Tue, 27 Jun 2017 17:50:05 GMT http://www.elated.com/forums/topic/6334#post26692
Re: Trouble with JS code http://www.elated.com/forums/topic/6332/#post26689 From: chrishirst


"my first problem is that when i update the VAT % (MVA %) the calculation does not capture the changed %. it continue with 25%. how is that?
"

the first thing would be to use the correct elements for numeric input, a textarea (#paid) is NOT appropriate and using the html content of the element only compounds the problem.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Sat, 24 Jun 2017 11:20:55 GMT http://www.elated.com/forums/topic/6332#post26689
Re: Build a CMS in an Afternoon with PHP and MySQL http://www.elated.com/forums/topic/5114/#post26688 From: matt


@athleticstatto: I didn't read @csturner's comment properly. I wouldn't recommend just removing mysql_escape_string() - that's a security risk!

I think the best approach, if you are using PHP7, is probably this:

https://phpdelusions.net/pdo#prepared


Code:
--------------------
$orders = ["name","price","qty"]; //field names
$key = array_search($_GET['sort'],$orders); // see if we have such a name
$orderby = $orders[$key]; //if not, first one will be set automatically. smart enuf :)
$query = "SELECT * FROM `table` ORDER BY $orderby"; //value is safe
--------------------


i.e. use an unescaped string for the ORDER BY, *but* make sure that the string is pulled from a list of allowed values.

--
Matt Doyle, Elated

View » | Reply »

]]>
Sat, 24 Jun 2017 07:42:11 GMT http://www.elated.com/forums/topic/5114#post26688
Trouble with JS code http://www.elated.com/forums/topic/6332/#post26687 From: Wenaaz


Hi! im kinda new to building website with js, and therefore need a bit help with an error on my page. first of all, check www.nettnota.no/

basically free invoice generator (Norwegian) for small companies.

- my first problem is that when i update the VAT % (MVA %) the calculation does not capture the changed %. it continue with 25%. how is that?

- second problem is, how to i make MVA beløp (VAT amount) to get 2 decimals? same goes for Saldo (balance) :S

below you can see the whole js coding:


Code:
--------------------
function print_today() {
var now = new Date();
var months = new Array('January','February','March','April','May','June','July','August','September','October','November','December');
var date = ((now.getDate()<10) ? "0" : "")+ now.getDate();
function fourdigits(number) {
return (number < 1000) ? number + 1900 : number;
}
var today = months[now.getMonth()] + " " + date + ", " + (fourdigits(now.getYear()));
return today;
}

// from http://www.mediacollege.com/internet/javascript/number/round.html
function roundNumber(number,decimals) {
var newString;// The new rounded number
decimals = Number(decimals);
if (decimals < 1) {
newString = (Math.round(number)).toString();
} else {
var numString = number.toString();
if (numString.lastIndexOf(".") == -1) {// If there is no decimal point
numString += ".";// give it one at the end
}
var cutoff = numString.lastIndexOf(".") + decimals;// The point at which to truncate the number
var d1 = Number(numString.substring(cutoff,cutoff+1));// The value of the last decimal place that we'll end up with
var d2 = Number(numString.substring(cutoff+1,cutoff+2));// The next decimal, after the last one we want
if (d2 >= 5) {// Do we need to round up at all? If not, the string will just be truncated
if (d1 == 9 && cutoff > 0) {// If the last digit is 9, find a new cutoff point
while (cutoff > 0 && (d1 == 9 || isNaN(d1))) {
if (d1 != ".") {
cutoff -= 1;
d1 = Number(numString.substring(cutoff,cutoff+1));
} else {
cutoff -= 1;
}
}
}
d1 += 1;
}
if (d1 == 10) {
numString = numString.substring(0, numString.lastIndexOf("."));
var roundedNum = Number(numString) + 1;
newString = roundedNum.toString() + '.';
} else {
newString = numString.substring(0,cutoff) + d1.toString();
}
}
if (newString.lastIndexOf(".") == -1) {// Do this again, to the new string
newString += ".";
}
var decs = (newString.substring(newString.lastIndexOf(".")+1)).length;
for(var i=0;i<decimals-decs;i++) newString += "0";
//var newNumber = Number(newString);// make it a number if you like
return newString; // Output the result to the form field (change for your purposes)
}

function update_total() {
var total = 0;
$('.price').each(function(i){
price = $(this).html().replace("","");
if (!isNaN(price)) total += Number(price);
});

total = roundNumber(total,2);

$('#subtotal').html(""+total);
var test4 = $('#subtotal').html();
var test5 = $('#paid').html() * 0.01;
var test6 = test4 * test5;
$('#total').html(""+test6);

update_balance();
}

function update_balance() {

var test1 = $("#subtotal").html();
var test2 = $("#paid").html() * 0.01;
var test7 = +test2 + 1;
var test3 = test1 * +test7;

$('.due').html(""+test3);

}


function update_price() {
var row = $(this).parents('.item-row');
var price = row.find('.cost').val().replace("","") * row.find('.qty').val();
price = roundNumber(price,2);
isNaN(price) ? row.find('.price').html("N/A") : row.find('.price').html(""+price);

update_total();
}

function bind() {
$(".cost").blur(update_price);
$(".qty").blur(update_price);
}

$(document).ready(function() {

$('input').click(function(){
$(this).select();
});

$("#paid").blur(update_balance);

$("#addrow").click(function(){
$(".item-row:last").after('<tr class="item-row"><td class="item-name"><div class="delete-wpr"><textarea>Item Name</textarea><a class="delete" href="javascript:;" title="Remove row">X</a></div></td><td class="description"><textarea>Description</textarea></td><td><textarea class="cost">0</textarea></td><td><textarea class="qty">0</textarea></td><td><span class="price">0</span></td></tr>');
if ($(".delete").length > 0) $(".delete").show();
bind();
});

bind();

$(".delete").live('click',function(){
$(this).parents('.item-row').remove();
update_total();
if ($(".delete").length < 2) $(".delete").hide();
});

$("#cancel-logo").click(function(){
$("#logo").removeClass('edit');
});
$("#delete-logo").click(function(){
$("#logo").remove();
});
$("#change-logo").click(function(){
$("#logo").addClass('edit');
$("#imageloc").val($("#image").attr('src'));
$("#image").select();
});
$("#save-logo").click(function(){
$("#image").attr('src',$("#imageloc").val());
$("#logo").removeClass('edit');
});

$("#date").val(print_today());

});
--------------------


--
Martin Vens

View » | Reply »

]]>
Thu, 22 Jun 2017 13:18:04 GMT http://www.elated.com/forums/topic/6332#post26687
Re: Extra Spaces on Page http://www.elated.com/forums/topic/6331/#post26686 From: chrishirst


". I have looked at the pages side-by-side and not seeing where the issue might be. Any help you can provide is GREATLY appreciated!"

Look at the rendered source code side by side to see what extra bits the M$ interference framework is adding.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Wed, 21 Jun 2017 11:13:20 GMT http://www.elated.com/forums/topic/6331#post26686
Extra Spaces on Page http://www.elated.com/forums/topic/6331/#post26684 From: ftbadolato


Hello,

First time poster...

I recently purchased a template, which you can see here:
http://re.eimpactweb.com/index.html

I am converting the template to a .ASPX Master Page, which I have started here:
http://re.eimpactweb.com/default.aspx

If you toggle between the two pages, you'll notice that the search box at the top is not right justified in the .ASPX page as it should be and there is additional white space between the main menu and the first set of images. I am not sure where these formatting inconsistencies are coming from. Other than the addition of some server-side code from the .ASPX page, the code should be identical. I have looked at the pages side-by-side and not seeing where the issue might be. Any help you can provide is GREATLY appreciated!

Thank you!

View » | Reply »

]]>
Tue, 20 Jun 2017 16:59:07 GMT http://www.elated.com/forums/topic/6331#post26684
Re: directories and paths http://www.elated.com/forums/topic/6330/#post26682 From: newbie1022


I have a folder called "HTML", where all my code files are stored. Usually, I go in there when I am writing something in an editor. I first save the work, put down the editor, go to that folder, and right click, and then click "open with". Is that folder the root directory?

--
Jim Williams

View » | Reply »

]]>
Fri, 16 Jun 2017 21:43:37 GMT http://www.elated.com/forums/topic/6330#post26682
Re: directories and paths http://www.elated.com/forums/topic/6330/#post26681 From: chrishirst


Okay,

Let's gauge how much you do know.

do you know what either of these are;

Site root, or document root directory?

Document level folder/directory?

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 16 Jun 2017 20:43:51 GMT http://www.elated.com/forums/topic/6330#post26681
Re: directories and paths http://www.elated.com/forums/topic/6330/#post26680 From: newbie1022


Clear as mud!

--
Jim Williams

View » | Reply »

]]>
Fri, 16 Jun 2017 20:01:35 GMT http://www.elated.com/forums/topic/6330#post26680
Re: directories and paths http://www.elated.com/forums/topic/6330/#post26679 From: chrishirst


Root relative addressing, which is always the same path no matter where it is called from in the website structure is always prefixed with a slash '/'

So, "/images/filename.ext is a root path to a file in the images folder that is in the root folder.

no leading slash "images/filename.ext" would reference a file in the folder as the document being accessed, as would a leading dot and a slash "./images/filename.ext"

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 16 Jun 2017 19:07:44 GMT http://www.elated.com/forums/topic/6330#post26679
directories and paths http://www.elated.com/forums/topic/6330/#post26678 From: newbie1022


I am having a problem with establishing a path to a file when the source is an image, or video. I see root directories, and such, but can't get my head around all that. Anybody got a tutorial on this? What I need is to know what to put in the line of code so the browser goes to the right file and folder. Thanks!

--
Jim Williams

View » | Reply »

]]>
Fri, 16 Jun 2017 14:33:32 GMT http://www.elated.com/forums/topic/6330#post26678
Re: Contact Form not working http://www.elated.com/forums/topic/6329/#post26677 From: chrishirst


Define "not working".

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 16 Jun 2017 09:22:53 GMT http://www.elated.com/forums/topic/6329#post26677
Contact Form not working http://www.elated.com/forums/topic/6329/#post26676 From: cwindfield


Can anyone PLEASE tell me why my contact form isnt working and how to make it secure? I have a php file on my server along with the form on my homepage index.html here is the php code saved in a php file called contact.php



Code:
--------------------
<?php
$field_name = $_POST['name'];
$field_email = $_POST['email'];
$field_about = $_POST['about'];
$field_message = $_POST['message'];

// Replace with your email adress here
$mail_to = 'chauncey@meetmckenziemason.com';

$subject = 'Message from a site visitor '.$field_email;

$body_message = 'From: '.$field_name."\n";
$body_message .= 'E-mail: '.$field_email."\n";
$body_message .= 'Talk about: '.$field_about."\n";
$body_message .= 'Message: '.$field_message;

$headers = 'From: '.$field_email."\r\n";
$headers .= 'Reply-To: '.$field_email."\r\n";

$mail_status = mail($mail_to, $subject, $body_message, $headers);

if ($mail_status) { ?>
<script language="javascript" type="text/javascript">
alert('Your message has been sent');
window.location = 'index.html';
</script>
<?php
}
else { ?>
<script language="javascript" type="text/javascript">
alert('Message failed!');
window.location = 'index.html';
</script>
<?php
}
?>
--------------------



And here is the form:


Code:
--------------------
<form id="main-contact-form" action="contact.php" method="post" name="contact" >
<div class="field">
<p>Name <span class="colored">*</span></p>
<input name="name" type="text" class="required" title="Please type your name." placeholder="Name...">
</div>

<div class="field">
<p>Email address <span class="colored">*</span></p>
<input name="email" type="text" placeholder="Email...">
</div>

<div class="field">
<p>Subject</p>
<input name="about" type="text" placeholder="Subject...">
</div>

<div class="field">
<p>Type a message <span class="colored">*</span></p>
<textarea name="message" cols="15" rows="5" class="required" placeholder="Message..." title="Please type a message."></textarea>
</div>

<div class="button-container">
<button class="btn btn-submit" type="submit" name="submit">Send Message </button>
</div>

</form>
--------------------



Also the web address is www.meetmckenziemason.com I used a simple html template that came with a mail form and its just not working. Can anyone help?

--
CW

View » | Reply »

]]>
Thu, 15 Jun 2017 21:40:01 GMT http://www.elated.com/forums/topic/6329#post26676
Re: Checkboxes and 'submit' button issues http://www.elated.com/forums/topic/6328/#post26675 From: steveby


Thanks for the help.

--
Stephen Berry

View » | Reply »

]]>
Tue, 13 Jun 2017 12:02:29 GMT http://www.elated.com/forums/topic/6328#post26675
Re: PHP Anonymous Functions: What Are They, and Why Use Them? http://www.elated.com/forums/topic/5562/#post26673 From: chrishirst


Provided the functions are not reiterative (calling an instance of themselves), there should be no problem.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Tue, 13 Jun 2017 02:29:17 GMT http://www.elated.com/forums/topic/5562#post26673
Re: How to php address book allow user to modify own record http://www.elated.com/forums/topic/6327/#post26672 From: chrishirst


https://www.google.co.uk/#q=php+address+book+tutorial

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Tue, 13 Jun 2017 02:27:03 GMT http://www.elated.com/forums/topic/6327#post26672
Re: Checkboxes and 'submit' button issues http://www.elated.com/forums/topic/6328/#post26671 From: chrishirst


Start with the submit button disabled and only enable it if the correct boxes are checked.

However the issue is moot, as it is in javascript and the answers can be seen by simply viewing the source code.

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Tue, 13 Jun 2017 02:25:58 GMT http://www.elated.com/forums/topic/6328#post26671
Checkboxes and 'submit' button issues http://www.elated.com/forums/topic/6328/#post26670 From: steveby


I am designing a quiz with checkboxes for selection, two being the correct answers, the others not. I have managed to have a message appear if either the two correct options are selected or if the wrong options are selected. My problem is simply clicking my 'check my answer' button with out selecting any checkbox results in the answer being shown. A message appears in either correct or incorrect options are selected stating the answer. I don't want users to see the answer unless they have selected checkboxes.

I have tried the following code:



Code:
--------------------
function quiz4() {
var a4 = document.getElementsByName('q4');
var a4answers = new Array();
var a4right = new Array('a','c');
var a4bool = true;

for(i = 0; i < a4.length; i++) {
if(a4[i].checked) {
a4answers.push(a4[i].value);
}
}

a4answers.sort();
a4right.sort();

if(a4answers.length == a4right.length) {
for(i = 0; i < a4answers.length; i++) {
if(a4answers[i] != a4right[i]) {
a4bool = false;
break;
}//end of if loop
}//end if for loop
} else {
a4bool = false;
}

if(!document.getElementsByName('q4').checked) {
document.getElementById('oCorrectAnswer4').innerHTML = "Please select A), B), C) or D).";
}

This fails to stop the answer being shown, despite the fact that I used an if statement to request users to select a checkbox. I can only assume it's the wrong type of if statement, or in the wrong place, or is incomplete.

I would appreciate any help in solving the issue of having checkboxes checked to see if selected, and if so if the correct ones are selected.

Thanks.
if(a4bool == true) {
correctAnswers++;
document.getElementById('oCorrectAnswer4').innerHTML = "Correct: The answers are A) Keyboard and C) Fingerprint Scanner.";
}//end if
else {
document.getElementById('oCorrectAnswer4').innerHTML = "Incorrect: The answers are A) Keyboard and C) Fingerprint Scanner.";
}// end else

var inputs = document.getElementsByName('q4');
for(var i = 0; i < inputs.length; i++) {
if(inputs[i].type == 'checkbox') {
inputs[i].disabled = true;
}
}
}//end of q4
--------------------


--
Stephen Berry

View » | Reply »

]]>
Mon, 12 Jun 2017 17:44:58 GMT http://www.elated.com/forums/topic/6328#post26670
How to php address book allow user to modify own record http://www.elated.com/forums/topic/6327/#post26669 From: learningb


Hi,

I would like to build address book with php, where user can edit/delete own records. and view all records.

Is there any sample/example regarding this.

Thanks
Learning b.

View » | Reply »

]]>
Mon, 12 Jun 2017 16:23:55 GMT http://www.elated.com/forums/topic/6327#post26669
Re: PHP Anonymous Functions: What Are They, and Why Use Them? http://www.elated.com/forums/topic/5562/#post26668 From: Vikarm


Hi,

Can I call anonymous function inside another anonymous function?

For example:

Code:
--------------------
$function1 = function() use() {
return 2;
};
$function2 = function() use() {
return 2 * $function1();
}
echo $function2();
--------------------


View » | Reply »

]]>
Mon, 12 Jun 2017 13:07:06 GMT http://www.elated.com/forums/topic/5562#post26668
Re: Build a CMS in an Afternoon with PHP and MySQL http://www.elated.com/forums/topic/5114/#post26665 From: athleticstatto


Thanks Matt

Do I just take out the reference to mysql_escape etc or delete the whole line I'm confused

View » | Reply »

]]>
Sat, 10 Jun 2017 07:36:13 GMT http://www.elated.com/forums/topic/5114#post26665
Re: Build a CMS in an Afternoon with PHP and MySQL http://www.elated.com/forums/topic/5114/#post26664 From: matt


@athleticstatto: I think @csturner's comment earlier might help you out here:

http://www.elated.com/forums/topic/5114/#post25897

Cheers,
Matt

--
Matt Doyle, Elated

View » | Reply »

]]>
Sat, 10 Jun 2017 00:05:14 GMT http://www.elated.com/forums/topic/5114#post26664
Re: Build a CMS in an Afternoon with PHP and MySQL http://www.elated.com/forums/topic/5114/#post26663 From: matt


@robnyc: Tutorial author here. Sorry you didn't get on with my ORM style! Bear in mind that it's just a tutorial to teach the basic concepts of putting together a CMS with PHP and OOP, so the classes are simplified and coalesced out of necessity.

The Article class is essentially the Active Record pattern from Martin Fowler's excellent "Patterns of Enterprise Application Architecture", with additional methods to handle the domain logic. I used Active Record because it's easy to understand and work with. It's also used in many popular frameworks, including Ruby on Rails and Laravel (in its Eloquent ORM).

I agree that in an ideal world - especially if working on an enterprise-class app - you would factor out the database access methods into a separate Data Mapper class, but as I say, this was designed to be a beginner tutorial.

That said, I've used this same Active Record pattern when building several quite complex web applications over the last 15 years (including elated.com!) and have rarely encountered scenarios where I've needed to resort to a separate mapper class.

All the best,
Matt

--
Matt Doyle, Elated

View » | Reply »

]]>
Sat, 10 Jun 2017 00:04:18 GMT http://www.elated.com/forums/topic/5114#post26663
Re: Build a CMS in an Afternoon with PHP and MySQL http://www.elated.com/forums/topic/5114/#post26662 From: robnyc


Things have changed with php in the last six years, however bad code is still bad code.

A tutorial should incite exploration and a desire to learn more but it should never teach someone the wrong way of doing something.

I won't use this site or this "tutorial" and I don't recommend anyone use it either.

View » | Reply »

]]>
Fri, 09 Jun 2017 15:37:20 GMT http://www.elated.com/forums/topic/5114#post26662
Re: Easy HTML Templates with Mustache http://www.elated.com/forums/topic/5480/#post26661 From: chrishirst


You have used a reference to the object rather a name or ID value that represents the object.

I don't use this 'mustache' so this is a guess, but you have probably used ObjVar (the object) rather than ObjVar.Name (a string property of the object.)

--
Chris.
So long, and thanks for all the fish.
http://webmaster-talk.eu/


View » | Reply »

]]>
Fri, 09 Jun 2017 14:25:39 GMT http://www.elated.com/forums/topic/5480#post26661