In HTML i need a random variable to be assigned and of that variable i want it to desplay a line of code i specify, kind-of like an IF-THEN command ex:
IF
A=1
Then
<html code here>
A=2
<html code here>
Kind of like that, i think its javascript but i havent learned that yet If you cant its ok.
Thanks in advance
~Genrail~
1
HTML Help
Started By Genrail, Apr 10 2011 02:23
3 replies to this topic
#1
Posted 10 April 2011 - 02:23
This place still exists?
#2
Posted 10 April 2011 - 08:12
HTML is a markup language, not a programming language... With the exception of a bit of IE specific styling trickery, it's not possible to use conditional statements.
Depending on exactly what you want to do you will either need to use a client-side script (i.e. javascript) or more likely, a server-side script (e.g. PHP)
If you do want to use PHP, the above example would be pretty easy to achieve:
If you tell me exactly what you want to achieve, then I might be able to help you further.
Depending on exactly what you want to do you will either need to use a client-side script (i.e. javascript) or more likely, a server-side script (e.g. PHP)
If you do want to use PHP, the above example would be pretty easy to achieve:
<?php if($a == 1){ ?> <!-- HTML GOES HERE --> <?php }elseif($a == 2){ ?> <!-- SOME OTHER HTML GOES HERE --> <?php } ?>
Spoiler
If you tell me exactly what you want to achieve, then I might be able to help you further.
Edited by Bob, 10 April 2011 - 08:14.
#3
Posted 10 April 2011 - 18:44
I really dont know what that code is anywhay
I am on the school techteam and i am the one incharge of maintaining the school server/website, (this means i get keys to the school server room. Yay! ) In my spare time i improve the site, and add new things. As we have been told we are the best team the school has seen, we have made a "game" of sorts. To challange new techteam members...
When the page opens it will display 1 of 5 things. That will change everytime you visit, thats all i need it to do really
I may need help with other things later
I am on the school techteam and i am the one incharge of maintaining the school server/website, (this means i get keys to the school server room. Yay! ) In my spare time i improve the site, and add new things. As we have been told we are the best team the school has seen, we have made a "game" of sorts. To challange new techteam members...
When the page opens it will display 1 of 5 things. That will change everytime you visit, thats all i need it to do really
I may need help with other things later
Edited by Genrail, 10 April 2011 - 18:46.
This place still exists?
#4
Posted 11 April 2011 - 18:27
Well a server side script would generally be the way to go about it... but you would need to make sure that PHP (or something else) is installed on the server.
You can try a simple test to see if is by putting this into a file, with extension .php
If PHP is installed, you should get a bunch of information about it when you load the page. From what I understand, you want 1 of 5 pieces of HTML to be displayed, chosen at random? This can be achieved with a slightly modified version of the code I posted earlier:
NOTE: Lines starting with 2 slashes ( // ) are comments.
If you want / have to use javascript, you can do something to the effect of:
You can try a simple test to see if is by putting this into a file, with extension .php
<?php phpinfo(); ?>
If PHP is installed, you should get a bunch of information about it when you load the page. From what I understand, you want 1 of 5 pieces of HTML to be displayed, chosen at random? This can be achieved with a slightly modified version of the code I posted earlier:
<?php // Assign a random number to the variable 'a' between 1 and 5 $a = rand(1, 5); // Determine which piece of HTML to display if($a == 1){ ?><!-- HTML CODE 1 --><?php }elseif($a == 2){ ?><!-- HTML CODE 2 --><?php }elseif($a == 3){ ?><!-- HTML CODE 3 --><?php }elseif($a == 4){ ?><!-- HTML CODE 4 --><?php }else{ ?><!-- HTML CODE 5 --><?php } ?>
NOTE: Lines starting with 2 slashes ( // ) are comments.
If you want / have to use javascript, you can do something to the effect of:
<script type="text/javascript"> // Math.random() picks a random number between 0 and 1 // Times that number by 5, and round downwards to get a random number between 0 and 4 var a = Math.floor(Math.random()*5); // Determine which piece of HTML to write to the body if(a == 0){ document.write('HTML CODE 1'); }else if(a == 1){ document.write('HTML CODE 2'); }else if(a == 2){ document.write('HTML CODE 3'); }else if(a == 3){ document.write('HTML CODE 4'); }else{ document.write('HTML CODE 5'); } </script>
Edited by Bob, 11 April 2011 - 18:28.
3 user(s) are reading this topic
0 members, 3 guests, 0 anonymous users