HTML/CSS How can I implement a website using HTML and CSS without functionality?

AI Thread Summary
To implement a website using HTML and CSS without functionality, one can either use a web design editor or write directly in text files. Key components include using the <style> tag in the <head> section for CSS and structuring content within the <body> section using HTML elements. Issues discussed include the proper use of attributes like rowspan in tables and the importance of setting image dimensions to control layout. The conversation also highlights the use of padding for spacing and the necessity of linking to valid image sources. Overall, the thread emphasizes foundational HTML and CSS techniques for creating a static website layout.
  • #51
Klaas van Aarsen said:
Yes. (Nod)

I wrote now an if-statement with all possible combinations, which are 27 :oops: When I tried examples to check if the result is correct then I noticed that the casesI have written at the end are not computed correctly. Can that be because I have written so many "else if" ? Or must there be an error at the code? 🧐
 
Technology news on Phys.org
  • #52
evinda said:
I wrote now an if-statement with all possible combinations, which are 27 When I tried examples to check if the result is correct then I noticed that the casesI have written at the end are not computed correctly. Can that be because I have written so many "else if" ? Or must there be an error at the code?

I don't think we can really write too many "else if"'s for the code to handle.
So there must be in an error in the code. 🧐

Btw, we have 2 checkboxes, 3 choices for the screen size, and 2 options for the operating system.
Doesn't that mean we should have 2 x 2 x 3 x 2 = 24 combinations? 🤔
 
Last edited:
  • #53
Klaas van Aarsen said:
I don't think we can really write too many "else if"'s for the code to handle.
So there must be in an error in the code. 🧐

Btw, we have 2 checkboxes, 3 choices for the screen size, and 2 options for the operating system.
Doesn't that mean we should have 2 x 2 x 3 x 3 = 36 combinations? 🤔

I wrote it again. I wrote each of the 36 combinations analytically. Now it doesn't work at all. 🧐
I don't know what I am doing wrong, I don't see any mistake at the code. Here is what I have written: https://pastebin.com/mpw6PDYw :unsure:
 
  • #54
evinda said:
I wrote it again. I wrote each of the 36 combinations analytically. Now it doesn't work at all.
I don't know what I am doing wrong, I don't see any mistake at the code. Here is what I have written: https://pastebin.com/mpw6PDYw

We can debug and step through the code to figure it out.
Right click on the web page and select Inspect Element.
Find where your javascript source code is and set a breakpoint.
Execute the scenario that fails, which should then stop in the debugger from where you can inspect all expressions, and step through the if statements to see if we land where we're supposed to be. 🤔
 
  • #55
Klaas van Aarsen said:
We can debug and step through the code to figure it out.
Right click on the web page and select Inspect Element.
Find where your javascript source code is and set a breakpoint.
Execute the scenario that fails, which should then stop in the debugger from where you can inspect all expressions, and step through the if statements to see if we land where we're supposed to be. 🤔

I found the typo I had, now every case of the if-statement works. Now an oher problem appears. :oops: I cannot click the first checkbox ("Apple"), only if I click first at the second one ("Samsung") and then I can click on "Apple"or in general if I click first any filter then I can click on "Apple". What could be the reason? 🧐It is not related to the if-stetements, is it? :unsure:
 
  • #56
evinda said:
I cannot click the first checkbox ("Apple")
What do you mean exactly? (Wondering)
 
  • #57
Klaas van Aarsen said:
What do you mean exactly? (Wondering)

I click the checkbox of "Apple" but it is not getting marked. If I click first any other filter and then I try to click the checkbox of "Apple" then it gets marked. 🧐
 
  • #58
evinda said:
I click the checkbox of "Apple" but it is not getting marked. If I click first any other filter and then I try to click the checkbox of "Apple" then it gets marked.
That sounds strange. It suggests that it was disabled somehow but is enabled later on. It is possible from html, css, and javascript. But it seems unlikely you'd have done that.
Do you have the page somewhere? 🤔
 
  • #59
Klaas van Aarsen said:
That sounds strange. It suggests that it was disabled somehow but is enabled later on. It is possible from html, css, and javascript. But it seems unlikely you'd have done that.
Do you have the page somewhere? 🤔

I found my mistake. Now it works! (Nod)
As for the Textboxes at the size of the screen do we have to include them in the if-statements? 🧐
 
  • #60
evinda said:
As for the Textboxes at the size of the screen do we have to include them in the if-statements?
I believe they are intended as a 3rd option yes. 🤔
 
  • #61
Klaas van Aarsen said:
I believe they are intended as a 3rd option yes. 🤔
Do we have to add at the if-statements the possible cases for "From" and "To" and the possible cases only for "From" and the possible cases only for "To" ?
So we check:
- From < 6.1 AND To < 6.1 then no product is shown.
- From < 6.1 AND To = 6.1 then "Apple" is shown.
- From < 6.1 AND To >= 6.2 then "Apple" and "Samsung" is shown.
- From = 6.1 AND To = 6.1 then "Apple" is shown.
- From = 6.1 AND To > 6.1 then "Apple" and "Samsung" is shown.
- From = 6.2 AND To >= 6.2 then "Samsung" is shown.
- From > 6.2 AND To > 6.2 then no product is shown.
- From <= 6.1 then "Apple" and "Samsung" is shown.
- From = 6.2 then "Samsung" is shown.
- From > 6.2 then no product is shown.
- To < 6.1 then no product is shown.
- To = 6.1 then "Apple" is shown.
- To >= 6.2 then "Apple" and "Samsung" is shown. Or can we combine the cases? 🧐
 
  • #62
evinda said:
Do we have to add at the if-statements the possible cases for "From" and "To" and the possible cases only for "From" and the possible cases only for "To" ?

Or can we combine the cases?
I think we actually have more cases.
For starters, what if the user filled in 6.15?
Or what if they did not fill in the from field at all?
Or what if they accidentally filled in something other than a number? (Sweating)

Let's focus on one product first.
And let's assume both fields were filled in with a number for now.
Then for the Apple device, I believe we can combine it all in:
- From <= 6.1 AND 6.1 <= To then "Apple" is shown.
- Otherwise "Apple" is not shown.

Doesn't that cover all cases for "Apple" (except the new cases that I came up with)? 🤔

Perhaps we can test that, and see what happens if we leave the from field empty.
And also test what happens if we put for instance "6,1" in the from field with a comma instead of a point, which could be a typical 'mistake' from the user. :unsure:
 
  • #63
Klaas van Aarsen said:
Let's focus on one product first.
And let's assume both fields were filled in with a number for now.
Then for the Apple device, I believe we can combine it all in:
- From <= 6.1 AND 6.1 <= To then "Apple" is shown.
- Otherwise "Apple" is not shown.

Doesn't that cover all cases for "Apple" (except the new cases that I came up with)? 🤔

Perhaps we can test that, and see what happens if we leave the from field empty.
And also test what happens if we put for instance "6,1" in the from field with a comma instead of a point, which could be a typical 'mistake' from the user. :unsure:

It doesn't seem to work.

In HTML I wrote:
Code:
   <input type="string" id="from" value="Από" size="1">  
   <input type="string" id="to" value="Έως" size="1"> 
   <button type="button" onclick="Function2()">Εφαρμογή</button>

In Javascript I wrote:
Code:
<script>
function Function2() { 
   if (document.getElementById("from") <= 6.1 && document.getElementById("to") >= 6.1){ 
       Apple.style.display = "block"; 
   } 
   else { 
       Apple.style.display = "none"; 
   } 
} 
</script>

I gave as example-input "from=6" and 'to=8" and "Apple" is not shown. What is the error? 🧐
 
  • #64
evinda said:
It doesn't seem to work.

I gave as example-input "from=6" and 'to=8" and "Apple" is not shown. What is the error?
It should be document.getElementById("from").value. 🤔
 
  • #65
Klaas van Aarsen said:
It should be document.getElementById("from").value. 🤔

Now it works! (Nod) I wrote the corresponding code for "Samsung". If we choose to write something in these textboxes, should the radio button be unchecked if it was checked previously?
Also do we have to add this part at the 36 cases I wrote before? We can't write that seperately because it won't be combined with the other filters, can we? (Thinking)
 
  • #66
evinda said:
Now it works! I wrote the corresponding code for "Samsung". If we choose to write something in these textboxes, should the radio button be unchecked if it was checked previously?

Actually, I'm not sure what is intended. Can you find out? (Wondering)
I'd expect there to be a separate radio button in front of the text boxes to make it a 3rd option, but there isn't. :unsure:

evinda said:
Also do we have to add this part at the 36 cases I wrote before? We can't write that seperately because it won't be combined with the other filters, can we?
We could see that if we combine both Apple and Samsung in an if-tree that it becomes unmanageable.
Suppose we have a separate if-tree for Apple and also a separate if-tree for Samsung. Then we can combine the text boxes into those if-trees can't we? 🤔
 
  • #67
Klaas van Aarsen said:
We could see that if we combine both Apple and Samsung in an if-tree that it becomes unmanageable.
Suppose we have a separate if-tree for Apple and also a separate if-tree for Samsung. Then we can combine the text boxes into those if-trees can't we? 🤔

Should the if-tree for Apple look as follows?
Code:
If Apple is chosen then: 
      If Large Screen is chosen 
             If at Checkbox we have From <= 6.1 AND 6.1 <= To  
                      If iOS is chosen 
                               then "Apple" is shown
Then we have to check also the cases that only two filters are chosen, and the case that only one filter is chosen. Is it right? 🧐
 
  • #68
evinda said:
Code:
If Apple is chosen then:
      If Large Screen is chosen
             If at Checkbox we have From <= 6.1 AND 6.1 <= To
                      If iOS is chosen
                               then "Apple" is shown
"Large Screen is chosen" and "at Checkbox we have From <= 6.1 AND 6.1 <= To" can't both be true at the same time can they? :unsure:
Perhaps it should be Large Screen is chosen OR (at Checkbox we have From <= 6.1 AND 6.1 <= To)?

evinda said:
Then we have to check also the cases that only two filters are chosen, and the case that only one filter is chosen. Is it right?
What do you mean? :unsure:
 
  • #69
Klaas van Aarsen said:
"Large Screen is chosen" and "at Checkbox we have From <= 6.1 AND 6.1 <= To" can't both be true at the same time can they? :unsure:
Perhaps it should be Large Screen is chosen OR (at Checkbox we have From <= 6.1 AND 6.1 <= To)?

I wrote the case for choosing "Apple" and the case for choosing "Samsung", and it works! (Nod) Do we have to write also the case if neither "Apple" nor "Samsung" is chosen? This cannot be included in the previous cases, can it? 🧐

For the first case, choosing "Apple" I wrote:
Code:
if (Apple is checked){ 
        if (Large Screen is cheched OR (FROM <= 6.1 AND TO >= 6.1)){ 
            if (iOS ic checked){ 
                Apple is shown  
            } 
            else if (Androis ic checked){ 
                Apple is not shown 
            }
            else { 
                Apple is shown 
            } 
        }   
        else if (Median nScreen is checked OR (FROM > 6.1 OR TO < 6.1)){ 
            Apple is not shown 
        } 
        else if (Median Screen is not checked AND Large Screen is not checked && FROM == "Από" && TO == "Έως") { 
            if (iOS is checked){ 
                Apple is shown  
            } 
            else if (Androis is checked){ 
                Apple is not shown 
            } 
            else { 
                Apple is shown 
            } 
        } 
    }

Is this right? 🧐
 
Last edited:
  • #70
evinda said:
I wrote the case for choosing "Apple" and the case for choosing "Samsung", and it works! (Nod) Do we have to write also the case if neither "Apple" nor "Samsung" is chosen? This cannot be included in the previous cases, can it? 🧐

For the first case, choosing "Apple" I wrote:
Code:
if (Apple is checked){
        if (Large Screen is cheched OR (FROM <= 6.1 AND TO >= 6.1)){
            if (iOS ic checked){
                Apple is shown
            }
            else if (Androis ic checked){
                Apple is not shown
            }
            else {
                Apple is shown
            }
        }
        else if (Median nScreen is checked OR (FROM > 6.1 OR TO < 6.1)){
            Apple is not shown
        }
        else if (Median Screen is not checked AND Large Screen is not checked && FROM == "Από" && TO == "Έως") {
            if (iOS is checked){
                Apple is shown
            }
            else if (Androis is checked){
                Apple is not shown
            }
            else {
                Apple is shown
            }
        }
    }

Is this right? 🧐
How about:
Code:
var showApple = false
if (Apple is checked) {
    if (Large Screen is checked OR (FROM <= 6.1 AND TO >= 6.1)) {
        if (iOS is checked){
            showApple = true
        }
    }
}
if (showApple) {
    Apple is shown
} else{
    Apple is not shown
}
Oh, and a radio button is supposed to always give a single selection, so we shouldn't be able to select both Medium Screen and Large Screen. 🤔
 
Last edited:
  • #71
Klaas van Aarsen said:
How about:
Code:
var showApple = false
if (Apple is checked) {
    if (Large Screen is checked OR (FROM <= 6.1 AND TO >= 6.1)) {
        if (iOS is checked){
            showApple = true
        }
    }
}
if (showApple) {
    Apple is shown
} else{
    Apple is not shown
}

So we define a local variable at the beginning of the function that has the value "false" and it gets the value "true" if the specific product should be shown. Is this the right idea of the way you described? 🧐
 
  • #72
evinda said:
So we define a local variable at the beginning of the function that has the value "false" and it gets the value "true" if the specific product should be shown. Is this the right idea of the way you described?
Yep. (Nod)

Alternatively we can put everything in a single if-statement and combine with AND and OR.
Something like:
Code:
if (Apple checked AND (Large screen selected OR (from <= 6.1 AND 6.1 <= to)) AND iOS selected) {
    show apple product
} else {
    hide apple product
}
🤔
 
  • #73
Klaas van Aarsen said:
Yep. (Nod)

Alternatively we can put everything in a single if-statement and combine with AND and OR.
Something like:
Code:
if (Apple checked AND (Large screen selected OR (from <= 6.1 AND 6.1 <= to)) AND iOS selected) {
    show apple product
} else {
    hide apple product
}
🤔
Ok! Which of the two ways do you suggest? Which one is better? 🧐
 
  • #74
evinda said:
Ok! Which of the two ways do you suggest? Which one is better?
Both are fine. :geek:

I expect we'll revisit it anyway since I suspect there is another stage coming up. Are we also going to write php code? :unsure:
 
  • #75
I want now to create the initial side that consists of the logo and a searchbox. I did this, but it is small and I don't really know how to change the size. I tried differend ways at css styles, but the height doesn't change. I can only change the length of the search box.

I wrote:
Code:
<input type="text" id="search" size="40">
              <button id="search"type="button"  style="background-color:red;color:white">
                  Search 
              </button>

How can we change the height? I tried to add also "height:..." but I didn't see any change. 🧐
 
  • #76
It shouldn't be an html attribute. Instead it should be css style. That is, either in the <style> section, or as a style="..." attribute.
Then font-size or height should work. They do need a unit like 'px' for pixels. 🤔
 
  • #77
Klaas van Aarsen said:
It shouldn't be an html attribute. Instead it should be css style. That is, either in the <style> section, or as a style="..." attribute.
Then font-size or height should work. They do need a unit like 'px' for pixels. 🤔

It works now! (Nod) Now I have a quesion about php (Blush)

In a .php file we have the filters and products with title, description and price that we had above. The file is in the form:
Code:
<?php 
$content = [ 
   "Mobile" => [ 
       "filters" => [ ... ] 
       "products" => [ ... ]  
    ] 
] 
?>

If we write in the searchbox above "Mobile" all mobiles should be shown. So do we write in an other .php file "if (input == Mobile)" then show these products otherwise no product should be shown, in the way we did it above with javascript with the different combinations of filters to show Apple and Samsung? But how do we combine these two files? :unsure:
 
  • #78
evinda said:
It works now!

Nice! (Nod)

evinda said:
Now I have a quesion about php

If we write in the searchbox above "Mobile" all mobiles should be shown. So do we write in an other .php file "if (input == Mobile)" then show these products otherwise no product should be shown, in the way we did it above with javascript with the different combinations of filters to show Apple and Samsung? But how do we combine these two files? :unsure:
We would basically replace the javascript code by php code and it will all still be one file.

We would have a special "Submit" button that posts the selections to the server.
The server will execute the php script and send the result back.
That is, the page will be shown again, but now the php script decides what to show instead of the javascript.

See the PHP intro on w3schools.
Ultimately our page should look like the example shown in the PHP Full Form page.
 
  • #79
Klaas van Aarsen said:
We would basically replace the javascript code by php code and it will all still be one file.

We would have a special "Submit" button that posts the selections to the server.
The server will execute the php script and send the result back.
That is, the page will be shown again, but now the php script decides what to show instead of the javascript.

See the PHP intro on w3schools.
Ultimately our page should look like the example shown in the PHP Full Form page.

So at the definition of the searchbox do we add a value to connect it with the server?

I mean:
Code:
<input type="text" id="input" value="<?php echo $input;?>">

:unsure:
 
  • #80
evinda said:
So at the definition of the searchbox do we add a value to connect it with the server?
I mean:
Code:
<input type="text" id="input" value="<?php echo $input;?>">
Not exactly. :unsure:
The value doesn't really connect it to the server.
Instead the value ensures that a user gets to see the same value they entered when the server generates a new page.
The connection to the server is when we respond to a "submit" button and pick up the value by its id="input". 🤔
That is, we still need php code somewhere else that uses $_POST["input"].
 
Last edited:
  • #81
Klaas van Aarsen said:
Not exactly. :unsure:
The value doesn't really connect it to the server.
Instead the value ensures that a user gets to see the same value they entered when the server generates a new page.
The connection to the server is when we respond to a "submit" button and pick up the value by its id="input". 🤔
That is, we still need php code somewhere else that uses $_POST["input"].

Do we need the value of the submit button or the searchbox? I mean where do we write id="input"? At the definition of the textbox of the searchbox or the submit button?
🧐
 
  • #82
evinda said:
Do we need the value of the submit button or the searchbox? I mean where do we write id="input"? At the definition of the textbox of the searchbox or the submit button?
The search box needs the id="input".
The submit button needs to be of type="submit".
Both need to be in a <form>, with a method="post", and an action that specifies the name of the .php file.
And we will need php code somewhere that uses $_POST["input"], which is the value entered in the search box after submitting. 🤔
 
  • #83
Klaas van Aarsen said:
The search box needs the id="input".
The submit button needs to be of type="submit".
Both need to be in a <form>, with a method="post", and an action that specifies the name of the .php file.
And we will need php code somewhere that uses $_POST["input"], which is the value entered in the search box after submitting. 🤔

Ok! The php code that uses $_POST["input"] must be in the file with name that we wrote in action, (action = "file.php"), is this right? 🧐

I tried to check that, writing in "file.php" the following code:
Code:
<html>
<body>
The input is: <?php echo $_POST["input"]; ?>
</body>
</html>

But I get as result the code exactly as it is, not "The input is: ... ". Do we have to write something more in the php file? 🧐
 
Last edited:
  • #84
evinda said:
Ok! The php code that uses $_POST["input"] must be in the file with name that we wrote in action, (action = "file.php"), is this right?

But I get as result the code exactly as it is, not "The input is: ... ". Do we have to write something more in the php file?
I don't think so. That should be enough.
We do need a <form> with a "submit" button in the original file. And specify the method to POST and specify the php file.
Perhaps the method is missing? :unsure:
 
  • #85
Klaas van Aarsen said:
I don't think so. That should be enough.
We do need a <form> with a "submit" button in the original file. And specify the method to POST and specify the php file.
Perhaps the method is missing? :unsure:

I have used the <form>, and I have also written the action and the method... What else could be wrong? 🧐
 
  • #86
evinda said:
I have used the <form>, and I have also written the action and the method... What else could be wrong?
I think we need name="input" instead of id="input". :unsure:
 
  • #87
Klaas van Aarsen said:
I think we need name="input" instead of id="input". :unsure:
I tried now also an example I found online: https://www.php.net/manual/de/tutorial.forms.php
So in an file with name example.html I wrote:
Code:
 <form action="action.php" method="post"> <p>Ihr Name: <input type="text" name="name" /></p> <p>Ihr Alter: <input type="text" name="alter" /></p> <p><input type="submit" /></p> </form>

and in a file with name action.php I wrote:

Code:
 Hallo <?php echo htmlspecialchars($_POST['name']); ?>. Sie sind <?php echo (int)$_POST['alter']; ?> Jahre alt.

Then running it we get:

what_we_get.png


So I get the code of the php-file.

What am I doing wrong? 🧐
 
  • #88
evinda said:
Then running it we get:

So I get the code of the php-file.
What am I doing wrong?
It looks as if your php file is interpreted as an HTML file.
The php-file must be executed as PHP code and not be shown as if it is an HTML file.
To achieve that, the php-file must typically be in the cgi-bin directory of the webserver, it must have been marked as an executable file, and the web server must have PHP enabled. 🤔
 
  • #89
Klaas van Aarsen said:
It looks as if your php file is interpreted as an HTML file.
The php-file must be executed as PHP code and not be shown as if it is an HTML file.
To achieve that, the php-file must typically be in the cgi-bin directory of the webserver, it must have been marked as an executable file, and the web server must have PHP enabled. 🤔

Is it possible to compile this in https://www.w3schools.com/ althrough we have two files, one html and one php? 🤔
 
  • #90
evinda said:
Is it possible to compile this in https://www.w3schools.com/ althrough we have two files, one html and one php?
I think we cannot test php on w3schools. :unsure:
We may need our own server that executes our php code. 🤔
Then again, there may be online php test locations.
 
  • #91
Klaas van Aarsen said:
I think we cannot test php on w3schools. :unsure:
We may need our own server that executes our php code. 🤔
Then again, there may be online php test locations.

Do I have to download something? Or how does this work? 🧐
 
  • #92
evinda said:
Do I have to download something? Or how does this work?

I've found a php compiler on w3schools now.
However, it doesn't seem to give us the option to create an html form and submit from there. :unsure:

If we want our own local web server, we can install apache. 🤔
 
  • #93
I have Apache installed on my system and I was able to create a search box so that the submit button runs a php script in cgi-bin:

1617404564347.png


1617404598199.png

:cool:
 
  • #94
Klaas van Aarsen said:
I have Apache installed on my system and I was able to create a search box so that the submit button runs a php script in cgi-bin:

View attachment 11045

https://www.physicsforums.com/attachments/11046
:cool:
Downloading Apache we get a file Apache -> httpd-2.4.35 -> httpd-2.4.35-o102p-x64-vc14 (and one httpd-2.4.35-o102p-x86-vc14 ) -> Apache24. In the last one there are several files. Do we save the php file that we write in the file "cgi-bin"? And where do we save the html file? Also there? 🧐
 
  • #95
evinda said:
Downloading Apache we get a file Apache -> httpd-2.4.35 -> httpd-2.4.35-o102p-x64-vc14 (and one httpd-2.4.35-o102p-x86-vc14 ) -> Apache24. In the last one there are several files. Do we save the php file that we write in the file "cgi-bin"? And where do we save the html file? Also there?
The html file should go to something like a /www/html/ directory, where there should already be an index.html file. 🤔
 
  • #96
Klaas van Aarsen said:
The html file should go to something like a /www/html/ directory, where there should already be an index.html file. 🤔

In the Apache24 file there is "htdocs" which includes an index.html file. Do you mean to save my html file there? :unsure:
 
  • #97
evinda said:
In the Apache24 file there is "htdocs" which includes an index.html file. Do you mean to save my html file there?
Yep. (Nod)
 
  • #98
Klaas van Aarsen said:
Yep. (Nod)

It doesn't work (Sweating)

I get:
1617441949100.png
I saved the two files like this:

1617442073968.png


1617442103685.png


Is this wrong? 🧐
 
  • #99
evinda said:
It doesn't work
I saved the two files like this:

Is this wrong?
That is correct. (Nod)

What do you get if you open http://localhost or http://localhost/index.html in your browser? 🤔
If Apache is working you should get a standard apache html page that shows 'It works!'
If that works, what do you get if you open http://localhost/example.html? 🤔
 
  • #100
Klaas van Aarsen said:
What do you get if you open http://localhost or http://localhost/index.html in your browser? 🤔
If Apache is working you should get a standard apache html page that shows 'It works!'
If that works, what do you get if you open http://localhost/example.html? 🤔

It doesn't work... I get:

1617449557426.png
 
Last edited:

Similar threads

Replies
3
Views
1K
Replies
3
Views
2K
Replies
4
Views
1K
Replies
3
Views
3K
Replies
2
Views
5K
Replies
22
Views
2K
Replies
1
Views
2K
Back
Top