How replace all attribute completely in jQuery - html

How could to replace all required="required" with data-test="done" in jQuery?
<div id="commentform">
<div>
<label>Comment:</label>
<textarea required="required"></textarea>
</div>
<p>
<label>Name</label>
<input type="text" required="required">
</p>
<p>
<label>Mobile:</label>
<input type="text">
</p>
</div>

Related

Why don't form tags work after a div

I have a form which has a div tag within it to help style the second part of my form into a second column. However my close form tag now doesn't work. Is there a reason why?
I have a localstorage.js which is working perfectly up until <div id="form-group">. Please, help! I'm so close to completing this page.
<div id="section">
<form id="franchiseForm" action ="javascript:void(0);" method="POST">
<div class="field">
<label for="fran_name">Franchise Name</label>
<input type="text" name="franchise_name" id="fran_name" placeholder="e.g One Delivery Leeds" pattern="[a-zA-Z]" autofocus required tabindex="1">
<br>
</div>
<div id="form-group">
<p>Opening Hours</p>
<div>
<label for="Monds"> Monday </label>
<input type="text" name="Mon" id="Mon" class="open_hours" placeholder="--:--" required tabindex="8">
<span>-</span>
<input type="text" name="Monday" id="Monday" class="open_hours" placeholder="--:--" required tabindex="9">
<hr />
</div>
<div>
<div class="line-separator"> </div>
<div class="field">
<input type="submit" value="Save">
</div>
</form>
You have unclosed div tags try closing them. close the <div id="form-group> and the div before <div class= "line-seprator">
You've forgotten to close a <div> tag. Use this:
<div id="section">
<form id="franchiseForm" action ="javascript:void(0);" method="POST">
<div class="field">
<label for="fran_name">Franchise Name</label>
<input type="text" name="franchise_name" id="fran_name" placeholder="e.g One Delivery Leeds" pattern="[a-zA-Z]" autofocus required tabindex="1">
<br>
</div>
<div id="form-group">
<p>Opening Hours</p>
<div>
<label for="Monds"> Monday </label>
<input type="text" name="Mon" id="Mon" class="open_hours" placeholder="--:--" required tabindex="8">
<span>-</span>
<input type="text" name="Monday" id="Monday" class="open_hours" placeholder="--:--" required tabindex="9">
<hr>
</div>
</div>
<div>
<div class="line-separator"> </div>
<div class="field">
<input type="submit" value="Save">
</div>
</div>
</form>
</div>
You can check markup errors with an HTML validator. This one is good enough for most cases.

How to render no-table HTML form into two columns with CSS using classes?

I am trying to format a two-column form so that:
the labels are above each input field or text area
everything in class col1 is in the column on the left
everything in class col2 is in the column on the right
everything in class col12 spans both columns
Here is the HTML code I need this to work with:
<div id="contactForm">
<form method="post" action="">
<h3>Contact us</h3>
<p>To send us a work order, fill in the form below.<br /><strong>All the (*) fields are mandatory.</strong></p>
<fieldset>
<div class="col1">
<label for="form_firstname">Firstname <span class="required">*</span></label>
<input type="text" id="form_firstname" name="form_firstname" value="" />
</div>
<div class="col2">
<label for="form_lastname">Lastname <span class="required">*</span></label>
<input type="text" id="form_lastname" name="form_lastname" value="" />
</div>
<div class="col1">
<label for="form_address">Address</label>
<input type="text" id="form_address" name="form_address" value="" />
</div>
<div class="col2">
<label for="form_city">City</label>
<input type="text" id="form_city" name="form_city" value="" />
</div>
<div class="col1">
<label for="form_email">Email <span class="required">*</span></label>
<input type="text" id="form_email" name="form_email" value="" />
</div>
<div class="col2">
<label for="form_phone">Phone <span class="required">*</span></label>
<input type="text" id="form_phone" name="form_phone" value="" />
</div>
<div class="col12">
<label for="form_attachment">Add Attachment <span class="form_attachment">*</span></label>
<textarea id="form_attachment" name="form_attachment" rows="5"></textarea>
</div>
<div class="col12">
<label for="form_message">Message <span class="required">*</span></label>
<textarea id="form_message" name="form_message" rows="5"></textarea>
</div>
<div class="col12">
<label for="form_message">Message <span class="required">*</span></label>
<input type="submit" value="Send" formnovalidate="formnovalidate" />
</div>
</fieldset>
</form>
</div>
How do I code the CSS to style this HTML as required?
Here is the code on JSFiddle.
Try this CSS:
#contactForm{
width: 80%;
}
label,.col1,.col2,.col12{display: block;}
.col1{ float:right;}
.col2{float:left;}
.col12{clear:both;}
textarea{
display: block;
width: 100%;
}
http://jsfiddle.net/rx2gjpdw/3/

button not displayed while creating html form

<body> <div id="div1"> <form id="f1">Personal Information<hr align="right" width="95%"> <div id="div2"><label>Name:</label><input id="text1" type="textbox" placeholder="First Name" size="20"> <input id="text2" type="textbox" placeholder="Last Name" size="20"><br/><br/></div> <div id="div3"><label>E-mail:</label><input id="text3" type="textbox" placeholder="EMail" size="20"><br/><br/></div> <div id="div4"><label>Date Of Birth:</label><input id="text4" type="textbox" placeholder="yyyy-mm-dd" size="20"><br/><br/></div> <div id="div5"><label>Other Details:</label><textarea id="text5" rows="10" cols="42" onkeyup=""/></div> <div id="div6"><input type="button" id="button1" value="Submit"></div>
but on writing this code button is not displayd what is wrong with the code
Textarea's end tag is required.
Replace
<textarea id="text5" rows="10" cols="42" onkeyup=""/>
for
<textarea id="text5" rows="10" cols="42" onkeyup=""></textarea>
Replace
<input type="button" id="button1" value="Submit">
For
<input type="submit" id="button1" value="Submit my form !">
You missed many tags, I am providing rectified code below.
<form id="f1">
Personal Information
<hr align="right" width="95%">
<div id="div2">
<label>
Name:
</label>
<input id="text1" type="textbox" placeholder="First Name" size="20">
<input id="text2" type="textbox" placeholder="Last Name" size="20">
<br/>
<br/>
</div>
<div id="div3">
<label>
E-mail:
</label>
<input id="text3" type="textbox" placeholder="EMail" size="20">
<br/>
<br/>
</div>
<div id="div4">
<label>
Date Of Birth:
</label>
<input id="text4" type="textbox" placeholder="yyyy-mm-dd" size="20">
<br/>
<br/>
</div>
<div id="div5">
<label>
Other Details:
</label>
<textarea id="text5" rows="10" cols="42" onkeyup="">
</textarea>
</div>
<div id="div6">
<input type="button" id="button1" value="Submit">
</div>
</form>
You missed Closing tags for Body, Form, Textarea and parent DIV.

put two input text in the same line

I'm using html and jquery mobile.here is the code:
<div data-role = "content">
<form action = "?" method="post" name="form" id = "form">
<fieldset>
<div data-role = "fieldcontain" class = "ui-hide-label">
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" placeholder="Name" />
</div>
<div data-role ="fieldcontain" class= "ui-hide-label">
<label for="surname">Surname</label>
<input type="text" name="surname" id="surname" value="" placeholder="Surname"/>
</div>
<div data-role ="fieldcontain" class= "ui-hide-label">
<label for="address">Address</label>
<input type="text" name="address" id="address" value="" placeholder="Address"/>
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for="birth-place">Birth Place</label>
<input type="text" name="birth-place" id="birth_place" value="" placeholder="Birth Place" />
</div>
<div data-role = "fieldcontain" class="ui-hide-label">
<label for="province">Province</label>
<input type="text" name="province" id="province" value="" placeholder="PR" />
</div>
<div data-role="fieldcontain" class="ui-hide-label">
<label for"date">Birth Date</label>
<input type="datetime" name="dt" id="dt" value="" placeholder="Birth Date" />
</div>
<div data-role="fieldcontain">
<fieldset data-role="controlgroup" data-type="horizontal">
<input type="radio" name="radio-choice-1" id="radio-choice-1" value="male" />
<label for="radio-choice-1">Male</label>
<input type="radio" name="radio-choice-1" id="radio-choice-2" value="female" />
<label for="radio-choice-2">Female</label>
</fieldset>
</div>
<div data-role="fieldcontain" data-type="horizontal">
<label for="select-choice-0"></label>
<select name="select" id="select">
<option value="politrauma">Politrauma</option>
<option value="cardiologico">Cardiologico</option>
<option value="neurologico">Neurologico</option>
</select>
</div>
</fieldset>
</form>
</div>
I'm not able to put in the same line two input text. I tried block grid but it didn't work
You should look at two column layout in jquerymobile:
jquerymobile.com/demos/1.0.1/docs/content/content-grids.html
Your code should be something like this:
<form action = "./includes/user_form.php" method="post" id = "form">
<div class="ui-grid-a">
<div data-role = "fieldcontain" class = "ui-hide-label ui-block-a">
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" placeholder="Name" />
</div>
<div data-role ="fieldcontain" class= "ui-hide-label ui-block-b">
<label for="surname">Surname</label>
<input type="text" name="surname" id="surname" value="" placeholder="Surname"/>
</div>
</div>
</form>
I know this question is kind of old but I just had the same problem and this is what worked for me:
<fieldset class="ui-grid-a">
<div class="ui-block-a">
<input type="text" id="" name="" value="">
</div>
<div class="ui-block-b">
<input type="text" id="" name="" value="">
</div>
You can even add some style to change the relative size of the field.
Just add floats to the divs:
<form action = "./includes/user_form.php" method="post" id = "form">
<div data-role = "fieldcontain" class = "ui-hide-label" style="float:left">
<label for="name">Name</label>
<input type="text" name="name" id="name" value="" placeholder="Name" />
</div>
<div data-role ="fieldcontain" class= "ui-hide-label" style="float:left">
<label for="surname">Surname</label>
<input type="text" name="surname" id="surname" value="" placeholder="Surname"/>
</div>
</form>
I'm using <span> wrapper around input with class that overrides display attribute of nested <div> (generated by jquery mobile). Also you must explicitly set width of input.
Example http://jsfiddle.net/FabyD/
CSS:
.inlineinput div {
display: inline;
}
HTML:
<div>
some text
<span class="inlineinput">
<input type='text' style='display: inline; width: 50px;' />
</span>
some text
<span class="inlineinput">
<input type='text' style='display: inline; width: 50px;' />
</span>
some text
</div>
DIVs are block elements - by default they take up 100% width. This makes the following elements appear on "the next line".
So, you need to move the second set on elements into the same DIV as the first (or re-style your DIVs with a fixed-width and use floats, but that's a little more challenging)
Another tip is checking out the data-type="horizontal" -type (no pun intended).
<fieldset data-role="controlgroup" data-mini="true" data-type="horizontal">
<div data-role="fieldcontain">
<label for="textinput11">
Something:
</label>
<input name="something" id="textinput11" placeholder="" value="" type="text">
</div>
<div data-role="fieldcontain">
<label for="textinput12">
Something else:
</label>
<input name="something_else" id="textinput12" placeholder="" value="" type="text">
</div>
</fieldset>

html5 validation form tag

"The for attribute of the label element must refer to a form control."
Honestly, I don't understand what's wrong with the markup. I've looked through so much of the W3's site and just can't get it.
Help?
HTML:
<form action="process.php" method="post">
<div>
<label for="name">Name</label><br />
<input type="text" value="" name="name" />
</div>
<div>
<label for="email">E-mail</label><br />
<input type="text" value="" name="email" />
</div>
<div>
<label for="message">Message</label><br />
<textarea name="message" cols="30" rows="4"></textarea>
</div>
<div>
<input type="checkbox" value="yes" name="newsletter" />
<label for="newsletter">Subscribe to newsletter</label>
</div>
<div>
<input type="submit" value="Submit" name="subscribe" />
</div>
</form>
You're missing the id attribute.
So to fix it, for example:
<input type="text" value="" name="email" id="email" />
That's it. Linky.
Thirtydot is correct; there is amissing id in your form. I have added all.
Check this:
<form action="process.php" method="post">
<div>
<label for="name">Name</label><br />
<input type="text" id="name" value="" name="name" />
</div>
<div>
<label for="email">E-mail</label><br />
<input type="text" id="email" value="" name="email" />
</div>
<div>
<label for="message">Message</label><br />
<textarea name="message" id="message" cols="30" rows="4"></textarea>
</div>
<div>
<input type="checkbox" id="newsletter" value="yes" name="newsletter" />
<label for="newsletter">Subscribe to newsletter</label>
</div>
<div>
<input type="submit" value="Submit" name="subscribe" />
</div>
</form>