I have a form field/checkbox and am unable to pass the boolean value even though it is selected.
<input type="checkbox" name="IsContactValid"
id=" IsContactValid"
<cfif
ContactView.GetIsContactValid()>CHECKED
</cfif>>
that will be transmitted to the receiving form if the box is checked.
Kindly help.
You can give the check box a value:
<input type="checkbox" name="IsContactValid" value="1"
id=" IsContactValid"
<cfif
ContactView.GetIsContactValid()>CHECKED
</cfif>>
that will be transmitted to the receiving form if the box is checked.
Related
my question is how to insert 'checked' to the radio input in Jinja2.
part of edituser.html
<input type="radio" name="level" value="user">User</input>
<input type="radio" name="level" value="admin">Admin</input>
var user passing information about user to render_template()
user = Users.query.filter_by(id=user_id).first()
return render_template('admin/users/editUser.html', user=user)
I have an idea about create radio inputs inside my function and return it with another variable..
What is best practice?
You will need some type of condition of course. Since you did not provide any condition, let us assume that your user object has an attribute called is_admin. Let's also assume you want the User radio checked if the user is not an admin, and the Admin radio checked if they are.
You can template in the "checked" attribute to the input with an inline conditional statement.
<input type="radio" name="level" value="user" {{'checked' if not user.is_admin else ''}}>User</input>
<input type="radio" name="level" value="admin" {{'checked' if user.is_admin else ''}}>Admin</input>
If user.is_admin == True then the admin radio will be checked, otherwise the user radio will be.
I wanna know how I run certain functions depending on the selected checkboxes. This is my visual template:
and this is the code I have for my template is called admin.html:
<div class="panel-body">
<p><button type="button" class="btn btn-black"><i class="fa fa-upload" </i> <span class="bold">IMPORT ALL</span></button> </p>
<p> Import selected reports:</p>
<p> <label><input type="checkbox" value=""> Cisco Backlog Report</label></p>
<p> <label><input type="checkbox" value=""> Planning & Standard</label></p>
<p> <label><input type="checkbox" value=""> Emo Trans Report</label></p>
<p> <label><input type="checkbox" value=""> Phyllis Report</label></p>
<p> <label><input type="checkbox" value=""> Purchase Order View</label></p>
<p> <label><input type="checkbox" value=""> On Hand Inventory</label></p>
<p> <label><input type="checkbox" value=""> Bill of Material</label></p>
<p> <label><input type="checkbox" value=""> Aged</label></p>
<p> <label><input type="checkbox" value=""> Shipment with Times</label></p>
<p><button type="button" class="btn btn-danger">Import</button> </p>
As I mentioned before, I got 10 functions that read several .csv reports and upload the data into models and I trigger them with the URL section. In my views.py I will show two examples:
def importpurchase(request)
Log logic here
def importcisco(request)
Log logic here
def importall(request) # this function is to import all
importpurchase(None)
importcisco(None)
You can receive list of selected checkboxes using request.POST.getlist('mycheckboxname'), you should give your checkboxes name and value accordingly to selected field ('Aged' for example):
<input type="checkbox" name="mycheckboxname" value="Aged">
Then you can call any function depending on what selected in list:
def func1(l,vals):
process_values_in_different_way(l, vals)...
def func2(l,vals):
process_values(l, vals)...
def MyView(request):
values=get_values_from_somewhere()
mylist=request.POST.getlist('mycheckboxname')
if 'Aged' in mylist:
func2(mylist, values)
elif anotherValue in mylist:
func2(mylist, values)
elif...
etc
EDIT(on your comments):
This is how django works: your client send request and you return response. This is called HTTP protocol. When IMPORT button is clicked your client send a form which contains all data entered by the user to the server. This data appears as a part of request object in your view. You can retrieve this data and you can do everything you want with this data. In my example process_values can, for example, select all 'Phyllis Report' objects and return them to response, as part of rendered template. There is no other way how you can do it. You cant just call on click function from server without request. To accomplish what you want you can try to split your logic and put part of it to javascript. You will be able to bound onclick listener to your button and then send requests through ajax to server. But this is a whole new story.
This might be useful: ajax and django
i got the list of checkboxs form taxlist.
it consist of the two objecs. when i check on the checkbox taxlist.taxprecent,taxlist.taxtype will bind to ng-model cartoder.tax like array
[$promise: Promise, $resolved: false]
0:Resource
__v:0\
_id:"5721d57d5b6691d0107f53c3"
createdAt:"2016-04-28T11:33:02.022Z"
isDeleted:false
modifiedAt:"2016-04-28T11:33:02.023Z"
taxpercent:15
taxtype:"vat"
__proto__:Object
1:Resource
__v:0
_id:"5721ed298ea69da01328cbbc"
createdAt:"2016-04-28T10:59:53.673Z"
isDeleted:false
modifiedAt:"2016-04-28T10:59:53.673Z"
taxpercent:10
taxtype:"service"
__proto__:Object
$promise:Promise
$resolved:true
length:2
__proto__:Array[0]
Html code
<span ng-repeat="item in taxlist">
<label>
<input type="checkbox" ng-model="cartorder.tax" ng-checked="{{item}}">{{item.taxtype}}
</label>
I dont know even how to start this. please help how bind this data
You can add ng-change
<label><input type="checkbox" ng-model="cartorder.tax" ng-checked="{{item}}" ng-change="onChange(cartorder);">{{item.taxtype}}</label>
js
$scope.onChange = function(cartorder){
};
<input id="isChecked" name="isChecked"
type="checkbox"></input><input name="_isChecked"
type="hidden" value="on"></input> <label for="isChecked">Checked</label>
I have this checkbox on the top of my *.html.
I want to use the value of "isChecked" input in a "form" like seting 1/0 (true/false) to a hidden input:
<form id="someForm" class="form xml-display form-inline"
th:action="#{/doSomething}" method="post">
.....
<input type="hidden" name="isChecked"
th:value="GET VALUE FROM THE GLOBAL CHECKBOX" />
.....
</form>
So can I do this without any JS?
Should I add an object in my java controller to the Model so I can set the value from the "isChecked" checkbox to it and then use the object in th:value="${objectFromJavaController}" for the hidden input ? I tried setting a th:object="${objectFromJavaController}" for the checkbox and then passing it to the hidden input but it didn't work (th:value = ${"objectFromJavaController"}) ?
So can someone help me ? Thanks in advance!
Surely somethin like this is simple enough?
<input id="newsletter" name="newsletter" type="checkbox" checked="yes" value="yes"/>
This brings back the same result. anything else would be no. (with PHP code telling them apart)
I have the following code in my form:
<form action="mail.php" method="POST">
Is there a way to add another submit button and let php know that if button1 is used it sends the data to mail.php while is button two is used it send the data to mail2.php ?
Thanks for the help
It would be correct to use the value of the radio-button, passing the parameter option, like:
<input type="radio" name="how" value="mail1" id="radio1"><label for="radio1">Name of parameter1</label>
<input type="radio" name="how" value="mail2" id="radio2"><label for="radio2">Name of parameter2</label>
and on the server:
$mail = $_POST['how']==mail1?'mail1':'mail2';
include($mail.'.php');