<fieldset style="width: 400px;">
<legend><h2>Form Validation</h2></legend>
<form>
<table>
<tr>
<td>Name:</td>
<td><input type="text" name="ime"></td>
</tr>
<tr>
<td>Username</TD>
<td><input type="text" name="username"></td>
</tr>
</table>
<input type="submit" value="Submit" name="send">
</form>
</fieldset>
I am currently making a form inside of a table... This is kind of new for me, since I don't know how to do it. Above is the code I have tried, and I need something like this.
If someone could get me on the right path, ill be really grateful.
Note: As you can see in the picture above, it needs to have colspan of 3, so they can all have equal width. I made a perfect one with just <form>, but i just found out we have to do it inside of a table...
The easiest way to do it is colgroup - there you can specify, how much of space of the table any column should take.
For your example it would be something like this: (plz note that I didn't feel all of needed rows)
<fieldset style="width: 400px;">
<legend><h2>Form Validation</h2></legend>
<form>
<table>
<colgroup>
<col width="40%"/>
<col width="60%"/>
</colgroup>
<tr>
<td>Name:</td>
<td><input type="text" name="ime"></td>
</tr>
<tr>
<td>Username:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Password:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Re-type password:</td>
<td><input type="text" name="username"></td>
</tr>
<tr>
<td>Gender:</td>
<td>
<input type="radio" id="male" name="gender" />
<label for="male">Male</label>
<input type="radio" id="female" name="gender" />
<label for="female">Female</label>
<input type="radio" id="other" name="gender" />
<label for="other">Other</label>
</td>
</tr>
<tr>
<td>Programming skills:</td>
<td>
<input type="checkbox" id="java"/>
<label for="java">Java</label>
<input type="checkbox" id="ruby"/>
<label for="ruby">Ruby</label>
<input type="checkbox" id="net"/>
<label for="net">.Net</label>
</td>
</tr>
</table>
<input type="submit" value="Submit" name="send">
</form>
</fieldset>
Related
I've been stuck for hours on a problem that might be actually simple but I can't manage to find the solution.
To be short, I want to know the index (ie the first / the second / the third etc...) of a checkbox when clicking on it.
Here's the jsfiddle showing what's currently working and what is not. I've tried many things but couldn't find the solution I'm looking for.
https://jsfiddle.net/cpydwqk3/2/ <div>(this example applies only for the class "admin" which applies herself on the checkbox "admin").
function usermodif(identifiant) {
alert($('.admin').index(this)); //return -1
}
$("tr").click(function() {
alert($("tr").index(this)); //work but applies on whole line
});
<table>
<caption>Utilisateurs</caption>
<tr>
<th scope="col">pseudo</th>
<th scope="col">points</th>
<th scope="col">points_session</th>
<th scope="col">admin</th>
<th scope="col">banni</th>
</tr>
<tr>
<th scope="row">firstguy</th>
<td><input type="text" name="points" value="45" id="points"></td>
<td><input type="text" name="points_session" value="6" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin" onclick="usermodif(this.className)"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
<tr>
<th scope="row">Nico</th>
<td><input type="text" name="points" value="21" id="points"></td>
<td><input type="text" name="points_session" value="21" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin" onclick="usermodif(this.className)" checked> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
<tr>
<th scope="row">anonyme</th>
<td><input type="text" name="points" value="0" id="points"></td>
<td><input type="text" name="points_session" value="0" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin" onclick="usermodif(this.className)"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
Thanks in advance guys!
Traverse first tp the closest TR. Than get that closest TR index.
TR has an index amongst TBODY TRs, but not the checkbox.
Also, never use inline JavaScript on* attributes, same as you hopefully don't use inline style attributes. JS and CSS should be in one place only, and that's their respective files or tags.
$(".admin").on("click", function() {
const $par = $(this).closest("tr");
alert($par.index());
});
<table>
<tr>
<th scope="row">firstguy</th>
<td><input type="text" name="points" value="45" id="points"></td>
<td><input type="text" name="points_session" value="6" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
<tr>
<th scope="row">firstguy</th>
<td><input type="text" name="points" value="45" id="points"></td>
<td><input type="text" name="points_session" value="6" id="points_session"></td>
<td><input type="checkbox" class="admin" name="admin"> </td>
<td><input type="checkbox" class="banni" name="banni"> </td>
</tr>
</table>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
This seems (and should be) simple, but I have no idea why the values for my radio buttons appear empty
<!DOCTYPE html>
<html>
<body>
<form method="post" action="action_page.php">
<table>
<tr>
<th>Intermediate</th><th>Advanced</th><th>No selection</th>
</tr>
<tr>
<td colspan="3">
<label for="td1">1. Bash</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="td1" id="td1" value="BashInter"/>
</td>
<td><input type="radio" name="td1" value="BashAdv"/>
</td>
<td><input type="radio" name="td1" value="" /></td>
</tr><tr>
<td colspan="3">
<label for="td1">2. C</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="td2" id="td2" value="CInter"/>
</td>
<td><input type="radio" name="td2" value="CAdv"/>
</td>
<td><input type="radio" name="td2" value="" /></td>
</tr><tr>
<td colspan="3">
<label for="td1">3. C++</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="td3" id="td3" value="C++Inter"/>
</td>
<td><input type="radio" name="td3" value="C++Adv"/>
</td>
<td><input type="radio" name="td3" value="" /></td>
</tr></table>
<input type="submit" value="Submit">
</form>
<p>If you click "Submit", the form-data will be sent to a page called "action_page.php".</p>
</body>
</html>
If run on W3Schools' (ugh) server, it correctly outputs the input.
e.g.
td1=BashInter&td2=CAdv&td3=
However, my server, for print_r($_POST); returns
[td1] => [td2] => [td3] =>
regardless of what is selected.
Looking at the HTTP headers confirms that nothing is being sent.
All other aspects of the form correctly send their values.
I have tried a number of variants in relation to the values, but nothing has altered the fact that no data actually appears to be sent by the radio buttons.
You didn't specified that your form must be send as a POST one, so used method is defaulted to GET.
Try with
<form action="action_page.php" method="POST">
Last radio button of every set has been kept empty and has black value.
Which means <input type="radio" name="td3" value="" /> needs to be replaced with <input type="radio" name="td3" value="Some value 3" />
So in case you are selecting last radio button from every set then obviously it wont return anything.
Apart from this there is not other problem as long as your HTML code is concerned. If you still face any problem please upload your PHP code as well.
I also suggest to give some some meaningful label to each radio.
Here is the code you may try
<!DOCTYPE html>
<html>
<body>
<form method="POST" action="action_page.php">
<table>
<tr>
<th>Intermediate</th><th>Advanced</th><th>No selection</th>
</tr>
<tr>
<td colspan="3">
<label for="td1">1. Bash</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="td1" id="td1" value="BashInter"/> BashInter
</td>
<td><input type="radio" name="td1" value="BashAdv"/> BashAdv
</td>
<td><input type="radio" name="td1" value="Some value 1" /> Some value 1</td>
</tr><tr>
<td colspan="3">
<label for="td1">2. C</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="td2" id="td2" value="CInter"/> CInter
</td>
<td><input type="radio" name="td2" value="CAdv"/> CAdv
</td>
<td><input type="radio" name="td2" value="Some value 2" /> Some value 2</td>
</tr><tr>
<td colspan="3">
<label for="td1">3. C++</label>
</td>
</tr>
<tr>
<td>
<input type="radio" name="td3" id="td3" value="C++Inter"/> C++Inter
</td>
<td><input type="radio" name="td3" value="C++Adv"/> C++Adv
</td>
<td><input type="radio" name="td3" value="Some value 3" /> Some value 3</td>
</tr></table>
<input type="submit" value="Submit">
</form>
<p>If you click "Submit", the form-data will be sent to a page called "action_page.php".</p>
</body>
</html>
Sorry, this is my jsfiddle.net link >> http://jsfiddle.net/2vw1035n/
Why my column keep frozen at right side ?
This is my table
#table {
margin-left: 260px;
border: none;
font-size: 14pt;
font-weight: bold;
font-family: 'bookman old style';
}
<form>
<div class="regisContent">
<table id='regisTable'>
<tr>
<td>
<label for="fname">Name</label>
</td>
<td>:</td>
<td>
<input type="text" name="fname" id="fname" placeholder="Input your name here.." id='textConf'/>
</td>
</tr>
<tr>
<td>
<label for="passw">Password</label>
</td>
<td>:</td>
<td>
<input type="password" name="passw" id="passw" placeholder="Input your password here.." id='textConf'/>
</td>
</tr>
<tr>
<td>
<label for="cnpass">Confirm Password</label>
</td>
<td>:</td>
<td>
<input type="password" name="cnpass" id="cnpass" placeholder="Please input your password again.." id='textConf'/>
</td>
</tr>
<tr>
<td>
<label for="email">Email</label>
</td>
<td>:</td>
<td>
<input type="text" name="email" id="email" placeholder="Input your email here.." id='textConf'/>
</td>
</tr>
<tr>
<td>
<label for="phone">Phone</label>
</td>
<td>:</td>
<td>
<input type="phone" name="phone" id="phone" placeholder="Input your telephone number here.." id='textConf'/>
</td>
</tr>
<tr>
<td>
<label for="gender">Gender</label>
</td>
<td>:</td>
<td>
<input type="radio" name="gender" id="male" value="male"> Male
<input type="radio" name="gender" id="female" value="female"> Female
</td>
</tr>
<tr>
<td>
<label for="address">Address :</label><br/>
<textarea rows="7" cols="57" name="address" id="address" placeholder="Input your address here.."></textarea>
</td>
</tr>
<tr>
<td>
<fieldset id =box>
<legend>Terms & Conditions:</legend>
<pre id=terms>
Welcome to our website. If you continue to browse and use this website,
you are agreeing to comply with and be bound by the our terms
and conditions of use, which together with our privacy policy govern Baggy
Bag Shop relationship with you in relation to this website.
</pre>
</fieldset>
</td>
</tr>
<tr>
<td>
<input type="checkbox" name="agreement" id="ck" value="agreement">
<label for="ck" class='textConf'>I agree with the terms and conditions stated above</label>
</td>
</tr>
<tr>
<td>
<input type="submit" value="Submit"onclick="validate()"/>
<input type="reset" value="Cancel"/>
<!--<input type="button" value="Poke" onmouseover="this.style.background='white'" onmouseout="this.style.background='gray'" />-->
</td>
</tr>
</table>
</div>
</form>
I can not post any images here since i got no reputation ..
i switched up your table format a little and applied a max-width onto the td's with the label. demo here: http://jsfiddle.net/2vw1035n/2/
<tr>
<td>
<label for="fname">Name</label>:
</td>
<td>
<input type="text" name="fname" id="fname" placeholder="Input your name here.." id='textConf'/>
</td>
</tr>
css:
tr>td:nth-child(1) {
max-width:100px;
}
hope this helps
How do I align the "remember me" box so that it comes to left side so that the checkbox should start with username and password text boxes start.
Current it is -
<tr>
<td colspan="2" class="buttons">
<label>
<input id="rememberme" name="rememberme" value="remember" type="checkbox" /> Remember me</label>
<input type="submit" name="login" value="Login" />
</td>
</tr>
Add a label around your "Remember Me" text and assign a class to it;
Then give that class the following style:
.aux {
float: left;
}
<tr>
<td colspan="2" class="buttons">
<label>
<input id="rememberme" name="rememberme" value="remember" type="checkbox" />
<label class="aux"> Remember me</label>
</label>
<input type="submit" name="login" value="Login" />
</td>
</tr>
Is this you're looking for?
you will need to remove margin for checkbox which is given by default
check for the first
Js Fiddle
.valign{
vertical-align: bottom;
}
input{
margin:0;
}
try to insert your form in a two columns table:
<table>
<tr>
<td>User Name:</td>
<td><Input type="text"/></td>
</tr>
<tr>
<td>Password:</td>
<td><Input type="password"/></td>
</tr>
<tr>
<td></td>
<td class="buttons">
<label><input id="rememberme" name="rememberme" value="remember" type="checkbox" /> Remember me</label>
<input type="submit" name="login" value="Login"/>
</td>
</tr>
fiddle: http://jsfiddle.net/2wj86k32/
<tr><td class="buttons"><label>Username</label></td>
<td><input id="rememberme" name="rememberme" type="text" /></td></tr>
<tr><td class="buttons"><label>Username</label></td>
<td><input id="rememberme" name="rememberme" type="text" /></td></tr>
<tr><td class="buttons"></td>
<td><input id="rememberme" name="rememberme" type="checkbox" /><label>remember me</label><input type="submit" value="Login" /></td></tr>
Is it your need ?
if you try my code below you can see that the background color is light blue and it occupies the whole page of a site, I want to resize it how can you do that? I mean that the color will fit to the same size where the fill up boxes are,
do i need to add this code: width="60%"
can you please tell me where can I add this? Thanks
<html>
<div style="color:red">[+validationmessage+]</div>
<p style="color:#4C4C4C;font-weight:bold">« You can subscribe here: »</p>
<p>[+MailChimp.message+]</p>
<div style="background-color:#CCDFED">
<form method="post" action="[~[*id*]~]">
<br/>
<table>
<tr>
<td><label style="margin:0.5em"> Email: </label></td>
<td><input type="text" name="mc_EMAIL" size="60"
maxlength="60" style="margin:0.1em" value="" /></td>
</tr>
<tr>
<td><label style="margin:0.5em"> Name: </label></td>
<td><input type="text" name="mc_FNAME" size="60"
maxlength="60" style="margin:0.1em" value="" /></td>
</tr>
<tr>
<td><label style="margin:0.5em"> Last Name: </label></td>
<td><input type="text" name="mc_LNAME" size="60"
maxlength="60" style="margin:0.1em" value="" /></td>
</tr>
<tr>
<td><label style="margin:0.5em"> Website: </label></td>
<td><input type="text" name="mc_URL" size="60" maxlength="60"
style="margin:0.1em" value="" /></td>
</tr>
<tr>
<td><label style="margin:0.5em"> </label></td>
<td><input type="submit" name="subscribe" size="60"
maxlength="60" value="Register" /></td>
</tr>
</table>
</form>
<p><br/></p>
</div>
</html>
Try this:
<form method="post" action="[~[*id*]~]" style="display:inline-block;background-color:#CCDFEF">
Remove the <div style="background-color:#CCDFED"> before the form and </div> after it.