using a div as a radio button - php

<div>
<table class='accor'>
<tr>
<td>Roll No.</td>
<td>12801</td>
</tr>
<tr>
<td>Name</td>
<td>XXXX</td>
</tr>
<tr>
<td>Class</td>
<td>MS</td>
</tr>
</table>
</div>
i want the above code as a radio button. the above code is running inside a php while loop with the data supplied from a database. (i also need to use checked=checked to match a predefined value.)
i am using the jquery ui buttonset style with the radio.
how can i achieve that?

$().buttonset takes all the input type='radio' elements inside the selector and makes a stylized button set out of them. For each of these elements, the associated label is placed on the display of the resulting button. So to have buttons with labels that aren't just a single line of text, just place the contents inside the label.
<form>
<div id="radio">
<input type="radio" id="radio1" name="radio" />
<label for="radio1">
<div>
<table class='accor'>
<tr>
<td>Roll No.</td>
<td>12801</td>
</tr>
<tr>
<td>Name</td>
<td>XXXX</td>
</tr>
</table>
</div>
</label>
<input type="radio" id="radio2" name="radio" checked="checked" />
<label for="radio2"><div>
<table class='accor'>
<tr>
<td>Roll No.</td>
<td>12801</td>
</tr>
<tr>
<td>Name</td>
<td>XXXX</td>
</tr>
</table>
</div>
</label>
</div>
</form>
JS:
$(function() {
$("#radio").buttonset();
});

try following (embed your code as you want):
$('.accor td').on("click",function(){
$('td').css('background-color','#eee');
var rowNumber = $(this).closest('tr').index();
setSelected(rowNumber);
});
function setSelected(rowNumber){
$('tr').eq(rowNumber).find('td').css('background-color','#ccc');
}
setSelected(2);
working fiddle here: http://jsfiddle.net/ZEwpE/2/
i hope it helps.

or another option to do that is:
$('.accor td').on("click",function(){
$('td').css('background-color','#eee');
var tr = $(this).parent();
$(tr).children().css('background-color','#ccc');
});
Get click event
Get parent (in your case it's )
Set css style to all childs of our
But it's only alternate (very similar) method:
jsfiddle

Related

How to edit multiple field from one blade form

Hello I have a form like the below image-
The HTML code for this is-
<table style="width:100%" class="table table-striped">
<tr>
<td><strong>First Name</strong></td>
<td>Test Name</td>
<td><a class="btn btn-success" href="#">Edit</a></td>
</tr>
<tr>
<td><strong>Last Name</strong></td>
<td>Test Name</td>
<td><a class="btn btn-success" href="#">Edit</a></td>
</tr>
<tr>
<td><strong>Username</strong></td>
<td>test_username</td>
<td><a class="btn btn-success" href="#">Edit</a></td>
</tr>
</table>
Now what I am trying here is when I click on edit button I only need to be able to edit that specific field and store the updated value to my database only. All I want to know is, each time I click my form submit button only the updated field value should be passed to my controller method. I can pass my field name by a hidden input.
(I know I can keep a hidden input field in a form and change the field value by javascript. But I need to know if there is any better approach.)
Can I implement this using only one form tag in my Laravel blade? If yes how can I implement this without any touch in JS?
Okay, so you can do this with a css trick, look that I have added the input hidden with css, and instead of the a tag I used a label that is linked to the input with the for and id attributes, so when the user clicks on the label it focus on the input and triggers the css input:focus that shows the input and hide the name.
All is wrapped by a single form that if you add a <button type="input">Send</button> will send all to the controller
But you've mentioned that you just want to send the data that has been changed, unfortunately I don't think that this is possible without javascript, but you should set the value of the input to the original value, so when updated it will update to the same value, no problem at all, acctually almost all edit forms works that way
input {
opacity: 0;
width: 0;
}
input:focus {
visibility: visible;
opacity: 1;
width: 100px;
}
input:focus + span {
display: none;
}
<form>
<table style="width:100%" class="table table-striped">
<tr>
<td><strong>First Name</strong></td>
<td>
<input id="first_name" name="first_name" value="Test Name" />
<span>Test Name</span>
</td>
<td>
<label for="first_name" class="btn btn-success" href="#">Edit</label>
</td>
</tr>
<tr>
<td><strong>Last Name</strong></td>
<td>
<input id="last_name" value="Test Name" />
<span>Test Name</span>
</td>
<td>
<label for="last_name" class="btn btn-success" href="#">Edit</label>
</td>
</tr>
<tr>
<td><strong>Last Name</strong></td>
<td>
<input id="username" value="test_username" />
<span>test_username</span>
</td>
<td>
<label for="username" class="btn btn-success" href="#">Edit</label>
</td>
</tr>
</table>
</form>

Checkbox select all checkboxes Laravel

Here is my problem:
In PHP Laravel I have a foreach loop that displays messages on the screen including a checkbox. Every message has its own checkbox. I also have a checkbox at the top of all the messages. I would like to assign a function to that checkbox to check all the checkboxes. I know this question has been asked in the past, but unfortunately those answers didn't work for me. Does someone have a solution for me?
I'm using: Laravel, Inspinia, Bootstrap 4
Thanks in advance!
Here is my code:
#if(count($messages) > 0)
<table class="table table-hover">
<thead>
<tr>
<th> </th>
//select all checkboxes
<th><input type="checkbox" class=""/></th>
<th>#sortablelink('title', trans('messages.title'))</th>
<th>#sortablelink('sender_user_id', trans('messages.sender'))</th>
<th class="d-none d-sm-table-cell">#sortablelink('created_at', trans('messages.sent_at'))</th>
</tr>
</thead>
<tbody>
#foreach ($messages as $message)
<tr id="messagesTable">
<td><i class="{{ $message->read ? 'far fa-envelope-open' : 'fas fa-envelope' }}"></i></td>
//the checkboxes who need to be selected
<td class="project-title">
<div class="checkbox p1-1">
<input type="checkbox" id="message_{{$message->id}}" name="message" value="{{$message->id}}">
<label for="message_{{$message->id}}"></label>
</div>
</td>
<td class="project-title">
{{$message->title}}
</td>
<td class="project-title">
{{ $message->sender ? $message->sender->name : ''}}
</td>
<td class="project-title d-none d-sm-table-cell">
{{$message->created_at->format('d-m-Y H:i')}}
</td>
</tr>
#endforeach
</tbody>
</table>
#endif
you can do it in jquery
first step
change this
//select all checkboxes
<th><input type="checkbox" class=""/></th>
to this
//select all checkboxes
<th><input type="checkbox" class="check_all"/></th> //just added a class to this element
Second step
add class_name to all your <input type="checkbox">
i mean <input type="checkbox" id="message_{{$message->id}}" name="message" value="{{$message->id}}"> changed to <input type="checkbox" id="message_{{$message->id}}" name="message" value="{{$message->id}}" class="custom_name">
NOTE: be sure that all your checkboxes has one class_name instead the one witch if we click it others checked!
Third step
add this in footer
<script
src="https://code.jquery.com/jquery-3.4.1.js"
integrity="sha256-WpOohJOqMqqyKL9FccASB9O0KwACQJpFTUBLTYOVvVU="
crossorigin="anonymous"></script>
<script>
$(".check_all").on("click", function(){
$(".custom_name").each(function(){
$(this).attr("checked", true);
});
});
</script>
I HPOE THIS WORKS FOR YOU...

clone column1 to column 2 using button

I need another name2 column where in it has a button(copy all) once you click it a dialog box will appear "Are you sure you want to copy |Yes/No". it'll clone the data from name to name2.
<table class="downpanel">
<thead>
<tr>
<th></th>
<th>Name</th>
<th></th>
<th>Name2</th>
<th></th>
<th colspan="">Count</th>
<th></th>
<th>Unit</th>
<th></th>
<th>Category</th>
<th></th>
<th>Data1</th>
<th></th>
<th>Data2</th>
<th></th>
<th></th>
</tr>
</thead>
<tbody>
<tr>
<td>
<input type="button" class="copyall">
</td>
<td>
<input type="text" size="25" name="name">
</td>
<td>
<input type="text" size="25" name="name2">
</td>
<td>
<input type="button" class="copy">
</td>
<td>
<input type="text" size="3" name="from">
</td>
<td>
<input type="text" size="3" name="to">
</td>
<td>
<input type="button" class="copy">
</td>
<td>
<select name="unit" style="width: 75px;">
<option value="blah">blah</option>
</select>
<br />
</td>
<td>
<input type="button" class="copy">
</td>
<td>
<select name="category" style="width: 275px;">
<option value="blah">blah</option>
</select>
<br />
</td>
<td>
<input type="button" class="copy">
</td>
<td>
<input type="text" size="10" id="datepicker" name="data1">
</td>
<td>
<input type="button" class="copy">
</td>
<td>
<input type="text" size="7" name="data2">
</td>
<td>
<input type="button" class="copy">
</td>
</tr>
</tbody>
</table>
http://jsfiddle.net/jakecigar/hq2GG/2/
check this http://jsfiddle.net/hq2GG/4/
var r = confirm("Are you sure you want to copy?");
in both copy and copy all
http://jsfiddle.net/hq2GG/6/
You are facing a mode mash up issue. You initiated your data using HTML and now you want to manipulate it via Javascript. The more complex your issues get, the more you will end up in coding chaos. This is NOT about mixing different coding practices but to break the conceptual rework by designing one part in HTML and the other in Javascript. So as javascript seems to be mandatory here first design everything as if your whole application would only consist of Javascript. Define a mode:
DOM-Node-Manipulation (would be state of the art and also easier for manipulation) OR
html compile style (using innerHTML)
Once you got a mode make your matrix a matrix. If you need to copy cells, respectively rows and columns, you need to be able to address those. In the DOM Model you could maintain a two-dimensional wrapper array, in the html compile style you would obviously fittle with IDs, such as cell1_3, which helps you to make use of the getElementById. At the point in time you are able to address elements, it is just a matter of formulating loops, to get things copied, moved or deleted in bulk mode.
Once you got all of the conceptional prework you can decide to prefill your html page with html (and not javascript) - however this must follow the rules you set yourself for the scripting mode.

Passing selected value to PHP form using <a> links instead of select/option

I'm creating a dropdown menu where each selection will be wrapped in links. The value selected needs to be passed to a php contact form but I'm not sure how to do this.
Normally, I'd just use the select-option method but I want to style the menu completely from scratch so is it possible to get the same functionality from just a regular html dropdown menu?
The desired values in question are in the 'Who are you?' section...
<div id="contact_info">
<form name="htmlform" method="post" action="./contact.php">
<table>
<caption>CONTACT</caption>
<tr>
<td valign="top">
<label for="your_name">Name:</label>
</td>
<td valign="top">
<input type="text" name="your_name" maxlength="50" size="23">
</td>
</tr>
<tr>
<td valign="top">
<label for="email">Email:</label>
</td>
<td valign="top">
<input type="text" name="email" maxlength="50" size="23">
</td>
</tr>
<tr>
<td valign="top">
<label>Who are you?:</label>
</td>
<td valign="top">
<a>
<p style="background:#ffffff;">I am...</p>
</a>
<a href="">
<p>an artist.</p>
</a>
<a href="">
<p>an educator.</p>
</a>
<a href="">
<p>a student.</p>
</a>
<a href="">
<p>a curator.</p>
</a>
<a href="">
<p>other...</p>
</a>
</td>
</tr>
</table>
<table>
<tr>
<td style="width:120px !important;"></td>
<td valign="top">
<label for="comments">Message:</label>
</td>
</tr>
<tr>
<td style="width:120px !important;">
<input type="submit" value="Submit">
</td>
<td valign="top">
<textarea name="comments" maxlength="1000" cols="44" rows="19"></textarea>
</td>
</tr>
</table>
</form>
</div>
You will need javascript to do this. As you have stated that your are not that fluent in javascript, I will use jQuery here to illustrate what you need to do in an easy way. Note that it can be done in plain javascript or using another library as well.
First you need to add a hidden field that will contain the value you want to submit with the rest of the form and then you need to use javascript to get the value of the selected option / click and put it in the hidden field:
I will also add an ID to the table cell to make selecting the right element and catching the events easier:
html:
<td valign="top" id="I_am_a">
<input type="hidden" name="I_am_a">
<a><p style="background:#ffffff;">I am...</p></a>
<p>an artist.</p>
<p>an educator.</p>
<p>a student.</p>
<p>a curator.</p>
<p>other...</p>
</td>
javascript (assuming jQuery is included):
$("#I_am_a a").on('click', function(e) {
e.preventDefault(); // prevent the default click action
$("#I_am_a input")
.val( $(this).find("p").text() ); // assign the text contents of the
// paragraph tag in the clicked a
// to the input element
});
Something like this should do it.

how can I get data in the table cell that is checked after submit

can someone give me help, please.
here's my basic html
<form action="addSomething.php" method="POST">
<table>
<tr>
<th>Add Data</th>
<th>Description</th>
<th>Quantity</th>
</tr>
<tr>
<td><input type="checkbox" name="data[]" value="sample1" /> </td>
<td class="desc">Newbie</td>
<td>2</td>
</tr>
<tr>
<td><input type="checkbox" name="data[]" value="sample1" /> </td>
<td class="desc">Pro</td>
<td>1</td>
</tr>
<tr>
<td><input type="checkbox" name="data[]" value="sample1"/> </td>
<td class="desc" > Master </td>
<td>1</td>
</tr>
<br/>
<input type="submit" name="add" value="SUBMIT"/>
.....
how can I get the one with the class "desc" and the column for quantity that is checked after submitting the form
because the only I can add when querying in mysql is the value of checkbox but I want also the value of the data in "Description" column and "Quantity" column
In my addSomething.php the code I have is
if(isset($_POST['add']))
{
foreach($_POST['data'] as $value)
{
$sql = "INSERT INTO tablename (column1) VALUES('$value');"
//query stuff
}
}
what I will do , Any hints guys?
you can give your checkboxes different values
<input type="checkbox" name="data[]" value="newbie" />
<input type="checkbox" name="data[]" value="pro" />
<input type="checkbox" name="data[]" value="master" />
and then in addSomething.php define an array
$names = array('newbie'=>'Newbie', 'pro'=>'Pro', 'master'=>'Master');
and use it in your sql
if(isset($_POST['add']))
{
foreach($_POST['data'] as $value)
{
$sql = "INSERT INTO tablename (column1) VALUES ('".$names[$value]."');";
}
}
this applies only if you don't want users to edit the decription and quantity on the frontend. if you do, you need to put inputs in there and give them unique names.
I'd advise something along the lines of:
<form action="addSomething.php" method="POST">
<table>
<tr>
<th>Add Data</th>
<th>Description</th>
<th>Quantity</th>
</tr>
<tr>
<td><input type="checkbox" name="data[0]" value="sample1" /> </td>
<td class="desc">Newbie<input type="checkbox" name="desc[0]" value="Newbie" /></td>
<td>2<input type="checkbox" name="quan[0]" value="2" /></td>
</tr>
<tr>
<td><input type="checkbox" name="data[1]" value="sample1" /> </td>
<td class="desc">Pro<input type="checkbox" name="desc[1]" value="Pro" /></td>
<td>1<input type="checkbox" name="quan[1]" value="1" /></td>
</tr>
<tr>
<td><input type="checkbox" name="data[2]" value="sample1"/> </td>
<td class="desc" > Master <input type="checkbox" name="desc[2]" value="Master" /></td>
<td>1<input type="checkbox" name="quan[2]" value="1" /></td>
</tr>
<br/>
<input type="submit" name="add" value="SUBMIT"/>
...
with php
if(isset($_POST['add']))
{
foreach($_POST['data'] as $i => $value) {
$desc = mysql_real_escape_string($_POST['desc'][$i]);
$quan = mysql_real_escape_string($_POST['quan'][$i]);
$sql = "INSERT INTO tablename (desc,quan) VALUES('$desc','$quan');"
//query stuff
}
}
You have to explicitly number your fields in html to preserve associacion of data with checkboxes.
What you could do is write Javascript that triggers an AJAX request to your server.
Otherwise, you won't be able to get values in prior submit.
That, is by far, very inefficient. Executing a query for each field in your table.
You will either have to put the description in a hidden field or read the description from the database.
I suggest the later option.
You'll need to include these values in a hidden input
<input type="hidden" name="whatever" value="whatever>"
as an example
I think the best way for your code is you create a javascript function and call it on submit of form :
<form action="addSomething.php" method="POST" onsubmit="return postVars()">
when you submit the form, this function will be called. create a 2 hidden forms like this :
<input type="hidden" name="description" id="description">
<input type="hidden" name="quantity" id="quantity">
give a unique id to your td s and pass the id to your js function. fill these inputs in your js function :
document.getElementById('description').value = document.getElementById('td_' + id + '_description').innerHTML;
document.getElementById('quantity').value = document.getElementById('td_' + id + '_quantity').innerHTML;
and in your server side just get description and quantity from $_POST.
hope it's been helpful ;)

Categories