Failed to use the checked attribute with <select multiple></select> - html

I waned to use the checked attribute with a <select multiple></select> but the checked attribute didn't work.
I don't know what I did wrong
<body>
<form action="" method="get">
<fieldset>
<label for="skill">Skill</label>
<select name="skills" id="skill" multiple>
<option checked value="html">Html</option>
<option value="css">Css</option>
<option value="jss">Javascript</option>
</select>
<br>
<input type="submit">
<input type="reset">
</fieldset>
</form>
Thank you

<option checked> should be <option selected>, as this is an option, not a checkbox

Use below code in order to work
<form action="/">
<label for="skills">Skill</label>
<select name="skills" id="skills" multiple>
<option value="volvo">Html</option>
<option value="Css">Css</option>
<option value="Javascript">Javascript</option>
</select>
<br><br>
<input type="submit" value="Submit">
</form>
Hold down the Ctrl (windows) or Command (Mac) button to select multiple options.

Related

label for radio won't make a new line

I'm quite new to the HTML. I have to make a simple booking form. I'm getting stuck at the 'radio checking' label. After the "optgroup label" I need the radio option on a new line with a simple yes or no option after a text. Whatever I try it won't work and the yes or no option are right after the optgroup options.
<label for="Aantal personen">Aantal personen</label>
<input id="Aantal personen" name="Aantal personen" type="number" min="1" max="10"><br>
<label for="Aankomstdatum">Aankomstdatum</label>
<input id="Aankomstdatum" name="Aankomstdatum" type="date"><br>
<label for="Verblijfsduur">Verblijfsduur</label>
<input type="range" name="weight" id="range_weight" step="2" min="2" max="20" oninput="range_weight_disp.value = range_weight.value">
<output id="range_weight_disp"></output><br>
<label for="Verzorging">Verzorging</label>
<select id="Verzorging" name="Verzorging">
<optgroup label="opties">
<option value="logies">Logies</option>
<option value="Logies met ontbijt">Logies met ontbijt</option>
<option value="Halfpension">Halfpension</option>
<option value="Volpension">Volpensension</option>
</optgroup>
<form id="radio">"Annuleringsverzekering"</label>
<label for="annuleringsverzekering">
<label for="opt1"><input id="opt1" type="radio" name="mw" value="ja" required>Ja</label>
<label for="opt2"><input id="opt2" type="radio" name="mw" value="nee" required>Nee</label>
</form>
I hope someone can explain what I'm doing wrong, thank you:)
Welcome to Stack Overflow, there are some problems with your code:
You're not closing the <select> tag.
You are closing the annuleringsverzekering label before you even open it.
Here's how you can fix it. Make sure that you also assign the label for annuleringsverzekering to an id.
<label for="Aantal personen">Aantal personen</label>
<input id="Aantal personen" name="Aantal personen" type="number" min="1" max="10"><br>
<label for="Aankomstdatum">Aankomstdatum</label>
<input id="Aankomstdatum" name="Aankomstdatum" type="date"><br>
<label for="Verblijfsduur">Verblijfsduur</label>
<input type="range" name="weight" id="range_weight" step="2" min="2" max="20" oninput="range_weight_disp.value = range_weight.value">
<output id="range_weight_disp"></output><br>
<label for="Verzorging">Verzorging</label>
<select id="Verzorging" name="Verzorging">
<optgroup label="opties">
<option value="logies">Logies</option>
<option value="Logies met ontbijt">Logies met ontbijt</option>
<option value="Halfpension">Halfpension</option>
<option value="Volpension">Volpensension</option>
</optgroup>
</select>
<form id="radio"><label for="annuleringsverzekering">Annuleringsverzekering</label>
<label for="opt1"><input id="opt1" type="radio" name="mw" value="ja" required>Ja</label>
<label for="opt2"><input id="opt2" type="radio" name="mw" value="nee" required>Nee</label>
</form>
you can add this CSS code to your form tag with radio Id:
display: block;
you can use this code to every element to have full line for it

Aligning Radio button/multiple Search boxes horizontally same line

So far everything is lined up except the last search box. I'm kinda new and it's taking me way to long to figure this out. I need to align all of my search boxes, drop downs, and radio buttons on the same line and centered. The search buttons and radio buttons keep moving to the line below. I added float left to the form and it brought the radio button up but it seems out of alignment. Ill be adding a calendar option and need it all on the same line. what's the best way to do this?
.table
{
float:left;
}
<div class="table">
<select>
<option value="Last Name">Last Name</option>
<option value="First Name">First Name</option>
<option value="Employee ID">Employee ID</option>
<option value="Job ID">Job ID</option>
<option value="Phone">Phone</option>
<option value="Ipad Number">Ipad Number</option>
</select>
<input type="text" name="text" class="Search" placeholder="Search Here" />
<input type="submit" class="submit" value="Search" />
<select>
<option value="Phones">Phones</option>
<option value="Tablets">Tablets</option>
<option value="Computers">Computers</option>
<option value="Cellphone">Cellphone</option>
<option value="Docks">Docks</option>
<option value="Monitors">Monitors</option>
<option value="Gloves">Gloves</option>
<option value="Sleeves">Sleeves</option>
</select>
</div>
<form>
<input type="radio" name="Before" value="male"> Before<br>
<input type="radio" name="After" value="female"> After<br>
</form>
<input type="text" name="text" class="Search" placeholder="Search Here" />
<input type="submit" class="submit" value="Search" />
This will put everything in one line.
.table {
display: inline-block
}
.Search {
width: 10%
}
<div class="table">
<select>
<option value="Last Name">Last Name</option>
<option value="First Name">First Name</option>
<option value="Employee ID">Employee ID</option>
<option value="Job ID">Job ID</option>
<option value="Phone">Phone</option>
<option value="Ipad Number">Ipad Number</option>
</select>
<input type="text" name="text" class="Search" placeholder="Search Here" />
<input type="submit" class="submit" value="Search" />
<select>
<option value="Phones">Phones</option>
<option value="Tablets">Tablets</option>
<option value="Computers">Computers</option>
<option value="Cellphone">Cellphone</option>
<option value="Docks">Docks</option>
<option value="Monitors">Monitors</option>
<option value="Gloves">Gloves</option>
<option value="Sleeves">Sleeves</option>
</select>
<input type="radio" name="Before" value="male"> Before
<input type="radio" name="After" value="female"> After
<input type="text" name="text" class="Search" placeholder="Search Here" />
<input type="submit" class="submit" value="Search" />
</div>
Forms are block elements. You can change this via CSS:
form { display: inline }
or
form {display: inline-block }

How do I change the background colour of two/more different fieldsets using HTML and CSS?

I have two field sets on float-left next to each other, I would like each of them to have a different background colour.
Obviously just changing the background colour of the fieldset changes all of them to the same colour, this is not what I want, as you can see I have assigned each fieldset with a name but I can't get the background colours to be different:
In CSS:
fieldset{
background-color: aquamarine;
border: none;
float: left;
font-style: italic;
In HTML:
</head>
<h1 span class="white">Info Day</span> <span class="blue">Registration</span></h1>
<body>
<form name="form1" onsubmit="return validateForm()" method="post">
<fieldset name="fieldset1">
<legend>Step 1</legend>
How many people will be attending?
<select name = step1 id="step1" onchange="showField()">
<option value="0">Please Choose</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br>
<div id="divName"></div>
<img id="check" src="check.png">
</fieldset>
</form>
<form name="form2" onsubmit="return validateForm()" method="post">
<fieldset name= "fieldset2">
<legend>Step 2</legend>
Would you like your company name on your badges?<br>
<input type="radio">Yes<input type="radio">No
<br>
<div id="company"></div>
Will anyone in your group require special accommodations?<br>
(if yes) Please explain below:<br>
<input type="radio" name="Yes" value="Yes">Yes<input type="radio" name="No" value="No">No
</fieldset>
</form>
fieldset[name=fieldset1]{
background-color: color;
}
fieldset[name=fieldset2]{
background-color: color2;
}
You'll want to define classes instead of names, then style those CSS classes. Here's a running example:
.fieldset1 {
background-color: aquamarine;
}
.fieldset2 {
background-color: green;
}
<h1 span class="white">Info Day</span> <span class="blue">Registration</span></h1>
<body>
<form name="form1" onsubmit="return validateForm()" method="post">
<fieldset class="fieldset1">
<legend>Step 1</legend>
How many people will be attending?
<select name=s tep1 id="step1" onchange="showField()">
<option value="0">Please Choose</option>
<option value="1">1</option>
<option value="2">2</option>
<option value="3">3</option>
<option value="4">4</option>
<option value="5">5</option>
</select>
<br>
<div id="divName"></div>
<img id="check" src="check.png">
</fieldset>
</form>
<form name="form2" onsubmit="return validateForm()" method="post">
<fieldset class="fieldset2">
<legend>Step 2</legend>
Would you like your company name on your badges?
<br>
<input type="radio">Yes
<input type="radio">No
<br>
<div id="company"></div>
Will anyone in your group require special accommodations?
<br>(if yes) Please explain below:
<br>
<input type="radio" name="Yes" value="Yes">Yes
<input type="radio" name="No" value="No">No
</fieldset>
</form>
I would use the class or id attributes for assigning CSS rules: <fieldset class="fieldset1"> or <fieldset id="fieldset1"> instead of <fieldset name="fieldset1">
Then in the CSS you can use this for classes:
.fieldset1 {
...
}
or this for IDs:
#fieldset1 {
...
}

html required attribute is not working with readonly

<form action="check_rooms1.php" method="post" name="search_room" class="form" >
<p>
<label for="checkin">Check in date</label>
<input name="checkin" type="text" id="checkin" placeholder="click to enter" readonly required>
</p>
<p>
<label for="checkout">Check out date</label>
<input name="checkout" type="text" id="checkout" placeholder="click to enter" readonly required>
</p>
<p>
<label for="beds">Hotel type</label>
<label for="hotel_type"></label>
<select name="hotel_type" id="hotel_type">
<option value="1" selected>1 star</option>
<option value="2">2 star</option>
<option value="3">3 star</option>
<option value="4">4 star</option>
<option value="5">5 star</option>
</select>
<input type="submit" name="search_button" id="search_button" value="Search">
</p>
</form>
required validation is not working. I am entering the dates using a jquery calendar. that is why I disabled text edit by giving read only. Is there any problem with readonly?
Thanks for the concern.The problem is solved by using the input type date . It gives a calendar to pick date and cannot misformat the date also

Add 'required' attribute to <select> element

I have a <select> dropdown in my HTML form. How do I add required attribute to my <select> element? I would like a pure HTML5 solution. I googled but I dont seem to find it.
Here is my fiddle.
The first <option> needs to be empty. Otherwise, required will see it as a value filled.
Example
<select required>
<option></option>
<option>1</option>
<option>2</option>
</select>
First of all you must insert empty field in movie list.and add required
HTML
<form id="book_tickets">
<fieldset>
<legend>Booking Details</legend>
<p>
<label for="movie_name">Choose Movie</label>
<select id="movie_name" name="movie_name" required>
<option></option>
<option value="Movie 1">Movie 1</option>
<option value="Movie 2">Movie 2</option>
<option value="Movie 3">Movie 3</option>
</select>
</p>
<p>
<label for="theaters">Theaters</label>
<input list="theaters" name="theaters" required>
<datalist id="theaters">
<option value="Inox" />
<option value="E Square" />
</datalist>
</input>
</p>
<p>
<label for="date">Select Date</label>
<input type="date" name="date" id="date" required />
</p>
<p>
<label for="email">Enter Email</label>
<input type="email" name="email" id="email" placeholder="abc#gmail.com" required />
</p>
<p>
<label for="tickets_quantity">Number of Tickets</label>
<input type="number" min="1" max="10" name="tickets_quantity" id="tickets_quantity" required />
</p>
<p>
<label>Total Price</label>
<span id="total_price"></span>
</p>
<p>
<input type="submit" id="book_tickets" value="Book Tickets" />
</p>
</fieldset>
</form>
The required attribute on select element: video demo
select element HTML5 here
referring to the first option, check out the placeholder label option demo