I created a popup box using jQuery. The popup box contains a button named submit.
1.In a table <td>, there are two buttons "Add the name" and "Add from list". When the user clicks "Add the name", a popup box will open and get the input from the user (namely text data).
2.After entering the text data in the popup box, they should press the submit button. On clicking submit, the input text entered by the user is displayed in a <div id="dynamic"></div> in a <td>. (See HTML below).
3.In the HTML below, the second <tr>: in a separate I put some text, i.first Aid notes with a check box ii.sent to sick bay with a check box iii.ambulance with a checkbox.
4.When the user clicks the submit button, the text data is displayed in the name <td> cell (See HTML below). But what I want is at the same time the above mentioned check box with label should bind in their respective <td>s in a table dynamically (See HTML below, I placed it in individual <td> (i.e when the user clicks the submit button the check box also should display, this should happen at every click on submit).
I don't know how to perform using Javascript or jQuery. Can any one please come up with code.
<table width="100%" cellpadding="0" cellspacing="0" id="rounded_border">
<tr>
<td colspan="4"><p><em>Please record the name</em></p></td>
</tr>
<tr>
<td><strong>Involved</strong></td>
<td><button>Add a name</button></td>
<td><p align=center>or</p></td>
<td>Add from list</td>
</tr>
<tr id="list" class="ir-shade"><div id="dynamic">
<td><span class="delete_icon">x</span>Atil</td>
<td>
<input id="firstaid" onclick="addtreatment();" type="checkbox"/>
FirstAid needed
</td>
<td>
<input class="sickbay" onclick="addtreatment();" type="checkbox"/>
Sent to Sick bay
</td>
<td>
<input class="ambulance" onclick="addtreatment();" type="checkbox"/>
Ambulance
</td>
</div>
</tr>
</table>
sample fiddle
This is what i required as ouptup,but it is displayed as in a single <td>,i want it to be happen that eack check box and their respective label in individual <td>.
How to do with jquery/javascript. Thanks.
That would be in your 'addtreatment' function, what code do you currently have there?
Related
I want to know how to add one particular column value as textbox in an AngularJS grid.
So, I am implementing an AngularJS grid as below:
<div>
<table>
<tr>
<th>
<td>Customer Account Number</td>
<td>Customer Name</td>
</th>
</tr>
<tbody>
<tr ng-repeat="item in data">
<td>{{item.CustomerAccNumber}}</td>
<td>{{item.CustomerName}}</td>
</tr>
</tbody>
</table>
<input type=button value="Add Row" ng-click="Add()"/>
So, in scenario 2 things happen:
By default I am getting few records as "Customer Account Number" and "Customer Name".
But there is an "Add Row" button on the same page I need to implement which adds a new row to the grid.
The first column "Customer Account Number" is a text box and second row is noneditable.
So, how to place textbox as a column only when adding a new row from button?
Let's say after adding add row my first column is coming as text box, so after entering the account number in the textbox on textchange it should fetch the customer account number and display it in the same row.
Can someone help me figure out how to put the textbox into one particular column in grid?
Can it be done the way I have implemented the grid?
I don't want to use nggrid.
I would do something like this:
First, in your Controller, in your Add() function, when you push a new row, add a field such as isEditable to allow you to differentiate between a newly added row in the UI.
$scope.Add = function() {
$scope.data.push({
'CustomerAccNumber': 1,
'CustomerName': '',
'isEditable': true // field to identify new row
})
}
Then in your markup, having that flg available, you can leverage ngIf, like so:
<tr ng-repeat="item in data">
<td ng-if="!item.isEditable">{{item.CustomerAccNumber}}</td>
<td ng-if="item.isEditable">
<input type="text" ng-model="item.CustomerAccNumber">
</td>
<td>{{item.CustomerName}}</td>
</tr>
it should fetch CustomerAccount number
As far as your third item, you can use ngBlur to make a call when the user clicks out of the box:
1) Define a function in your controller to call when the user leaves the box.
$scope.doSomethingWithAccNumber() {
// $http call, etc
}
2) Update your textbox to use the ngBlur directive that will trigger when the user clicks out.
<td ng-if="item.isEditable">
<input type="text"
ng-model="item.CustomerAccNumber"
ng-blur="doSomethingWithAccNumber()">
</td>
If you want other keys to trigger this, you can use ngKeydown as well. Use of this is outlined well here. For example, you would want to add ng-keydown="$event.keyCode === 13 && doSomethingWithAccNumber()" to your input to trigger on Enter.
I am taking inputs in the main form which consists of a checkbox.
Before submitting the form i am showing a popup to confirm the submission.
I am unable to populate the checkbox field on the popup
var target = jQuery ('div#confirm_popup div.content');
code for populating the popup:
target.find('randomCheckboxMain').html(form_table.find('#randomCheckbox:checked').val());
here i am finding the check box in main form and then fetching its value and populating the pop up.
this is my main form checkbox, it is part of table with id="form_table"
<table id="form_table">
....
....
<tr>
<td class="field_head">checkh:</td>
<td>
<html:checkbox property="prop" name="randomCheckboxMain" value="yes" disabled="true"></html:checkbox>
</td>
</tr>
this is my popup field
<tr>
<td class="head">checkValue:</td>
<td class="randomCheckbox"></td>
</tr>
Can anyone tell me what i am doing wrong.
you use of class in <td class="randomCheckbox"></td>
So :
change :
.html(form_table.find('#randomCheckbox:checked').val());
To :
.html(form_table.find('.randomCheckbox:checked').val());
You have a class in your td, but you have id in the jQuery.
target.find('.randomCheckbox').html(
form_table.find('[name="randomCheckboxMain"]').val());
Give a ID or class to the checkbox to check easily if it is checked.
I've researched about this for a while now but I haven't really gotten my head wrapped around it as an amateur in design. How do make my following markup editable after after the user clicks on the 'Edit' button I had created. So here it is:
<div class='wrapper'>
<div class='topinfobar'>
<p>Contact Info</p>
</div>
<table>
<tbody>
<tr><td><p class='leftspacing'>Cellphone Numbers</p></td><td><p>072 215 3372</p></td>
<tr><td><p class='leftspacing'>Phone Numbers</p></td><td><p>011 310 9967</p></td>
<tr><td><p class='leftspacing'>email address</p></td><td><p>s.nyama9#gmail.com</p></td>
</tbody>
</table>
<button>Change</button>
</div>
I wanna be able to change only the Cellphone Numbers etc. by just pressing the Edit button I had created. I'm using php, I just did that markup for design purposes. And I want the button to change from 'Change' to 'Done' while the user is still editing their details. So, the info is only readable before you click on the Edit button and it changes to 'Done' after the user had clicked it
You can put those values in inputs but it's look like regular content using readonly attribute and css, and just toggle class and the attribute.
$('#edit').click(function(){
$('#form').toggleClass('view');
$('input').each(function(){
var inp = $(this);
if (inp.attr('readonly')) {
inp.removeAttr('readonly');
}
else {
inp.attr('readonly', 'readonly');
}
});
});
.view input {
border:0;
background:0;
outline:none !important;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div class='topinfobar'>
<p>Contact Info</p>
</div>
<table id="form" class="view">
<tbody>
<tr>
<td>
<p class='leftspacing'>Cellphone Numbers</p>
</td>
<td>
<p><input type="text" value="072 215 3372" readonly/></p>
</td>
</tr>
<tr>
<td>
<p class='leftspacing'>Phone Numbers</p>
</td>
<td>
<p><input type="text" value="011 310 9967" readonly/></p>
</td>
</tr>
<tr>
<td>
<p class='leftspacing'>email address</p>
</td>
<td>
<p><input type="email" value="s.nyama9#gmail.com" readonly/></p>
</td>
</tr>
</tbody>
</table>
<button id="edit">Change</button>
There are a number of different ways you can do this, but the "classical" way would be to put the values in <input/> tags with IDs that are styled to be transparent. Wrap the whole table in a form, then use JavaScript when the user clicks the button to remove a disabled property from each of the input fields and change the button label. The second click of the button would then be validation and/or a form submit. The easiest way to keep track of which is the first and second click would be to compare text, but you might want to just set a variable on the element instead. Try here for a good starting point on pure-Javascript form submission or here for JQuery. This is a Stack-Overflow question about making input fields transparent.
I am using JSP and Struts2.
If the user selects the checkbox without clicking on hyperlink, user should get the error msg above the checkbox line.
I think on click of hyperlink I should call one function which sets the global var to true. onclick of checkbox, I should call a function which checks the var val and if this is false error should display.
In case of checkbox uncheck error should not be visible.
Its like a terms and we want that user should click on hyperlink to see terms.
<tr>
<td colspan="2" style="padding-left: 3%;">
<s:text name="Text1" />
<s:text name="Text2" />
<s:text name="Text3" />
</td>
</tr>
<tr>
<td colspan="2" style="padding-left: 3%;"><s:checkbox name="isT" id="isT" label="isT" value="%{isT}" tabindex="12" /> <s:text name="isTer" />
</td>
</tr>
Why dont you enable checkbox on click of hyperlink. Till that time disabled the checkbox.
I have a form with a number of user-fillable fields. The user needs to enter a number in those fields that is selected from a pop-up window containing a large table of data.
For example, one field might say "Tax rate." The user would (preferably) click on the (empty) "tax rate" input field, which would bring up the large table of data. The user would (preferably) click on one of the values in that table which would then close the table and populate the input field with the value.
What I'm hoping (reaaallllyy hoping) is that I don't have to create some sort of special id for each cell in the table in order to pass the number back to the form field, because the tables are huge, and I hope to create them in plain old <tr><td>1.234</td></tr> format.
I smell jQuery but I'm not familiar with exactly how to implement it. Any help would be greatly appreciated.
Here's a very rudimentary demo using jQueryUI dialog that might get you started:
HTML:
Rate:<input type="text" id="rate_input" />
<div id="dialog" title="Click a value to fill input and close dialog">
<table id="rates" border="1" width="100%">
<tr>
<td>Value 1</td>
<td>Value 2</td>
<td>Value 3</td>
</tr>
</table>
</div>
jQuery:
$(function(){
$('#dialog').dialog({
autoOpen: false,
width: 400
});
$('#rate_input').click(function () {
$('#dialog').dialog('open');
});
$('#rates td').click(function () {
$('#rate_input').val($(this).text());
$('#dialog').dialog('close');
});
});
DEMO: http://jsfiddle.net/5jMqJ/