Help with basic Hello.html script

Discussion forum for all Windows batch related topics.

Moderator: DosItHelp

Post Reply
Message
Author
Phoenizz
Posts: 2
Joined: 05 May 2018 19:07

Help with basic Hello.html script

#1 Post by Phoenizz » 05 May 2018 19:35

Code: Select all

@echo off
echo What name do you want to display?
set /p name=
echo Your name is %name%!
echo What color red, green or blue?
set /p color=
echo You chose %color%
echo What font size do you want?
set /p fontsize =
echo You chose %fontsize%pt as fontsize
set "html=^<html^> ^<body^> ^<p^> ^<span style='fontsize:%fontsize%pt'^>Hello^</span^> ^<span style>='color:%color%'>%name%^</span>^</p> ^</body> ^</html> makehtml.html 
echo Hello, %name%  > hello.htm
pause
I'm new to batch files and I have not been able to change the font size or color successfully, so if someone could help me very appreciated.

P.S The aim of the script is to run in two modes interactively and non interactively, so above there's the interactive mode, where the aim is to ask the user for their name, the color they want and font size, after that if the user answered everything correctly a html page would open Saying Hello, "Name". The non interactively mode is supposed to run the same thing after the user enters for example "Hello.bat "David" blue 40 " in the console, which I have not been able to do as well.

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help with basic Hello.html script

#2 Post by aGerman » 06 May 2018 04:27

Batch:
- every single < and > needs to be escaped in your html text
- there must not be a space between variable name and equal sign in a SET /P statement
- you need to redirect the content of your html variable to the file using ECHO and >
- closing quote missing in your SET statement

HTML (off-topic in this forum):
- there must not be a > between style and =
- there is no fontsize property (it's font-size)

Next time please correct those typos by your own.

Code: Select all

@echo off &setlocal
echo What name do you want to display?
set /p name=
echo Your name is %name%!
echo What color red, green or blue?
set /p color=
echo You chose %color%
echo What font size do you want?
set /p fontsize=
echo You chose %fontsize%pt as fontsize
set "html=^<html^> ^<body^> ^<p^> ^<span style='font-size:%fontsize%pt'^>Hello^</span^> ^<span style='color:%color%'^>%name%^</span^>^</p^> ^</body^> ^</html^>"
>"hello.htm" echo %html%
pause
Steffen

Phoenizz
Posts: 2
Joined: 05 May 2018 19:07

Re: Help with basic Hello.html script

#3 Post by Phoenizz » 06 May 2018 12:31

Thanks Steffen, sorry about those Rookie mistakes,just one thing how do I get "Hello" and "name" to change color and font size, right now only Hello is changing font size and only the name is changing. I can see why that is, I have been trying to move

Code: Select all

^<span style='color:%color%'^>
to the right place, but already tried multiple things and still can't get the result I want.

Thanks for the help

aGerman
Expert
Posts: 4678
Joined: 22 Jan 2010 18:01
Location: Germany

Re: Help with basic Hello.html script

#4 Post by aGerman » 06 May 2018 13:50

As I wrote, HTML is off-topic in this forum...
You have 2 span tags in your source text. Why not only have one with both settings for color and font size?

Hint: Write the HTM file by hand first and see how it behaves.

Steffen

Post Reply