I would like to do a multiple search query usig multiple checkboxes which represent particular textboxes.
How do i create a mysql query which will be filtering the checked and unchecked checkboxes (probably using if statements)?
The query should be able to filter the checked and ucnchecked boxes and query them using the AND condition.
Thanks
Mysql won't be able to handle your html form post. You will need to use a server-side language to check for those checkboxes being set and then modify your query with additional conditions.
You would likely get a better response if you were more specific, but I'll throw you an example with php. Assuming your form looks something like:
<form method="post">
<input type="checkbox" name="field1_cb" value="1" />
<input type="text" name="field1_txt" />
<br /><br />
<input type="checkbox" name="field2_cb" value="1" />
<input type="text" name="field2_txt" />
</form>
Your server code might look something like:
$query = "SELECT * FROM tbl WHERE field0 = 'asdf' ";
$fields = array('field1','field2');
foreach($fields as $f){
if(isset($_POST[$f.'_cb'])){
$query .= " AND $f = ".$_POST[$f.'_txt'];
}
}
//Run your query...
Please don't copy and paste this code directly, it is disgustingly insecure. Just trying to get you started.
Related
I have an input that's in form. I enter the URL adress into this input, click sumbit, and below it shows if this address is available or not. This is done.
Now I want to make this information show up automatically (without clicking submit), after making a change in the input? I would also like the value in the input to not disappear after checking. How can I do that?
I would like it to look more or less like this, but instead of email correctness, URL availability - https://youtu.be/HzJngc-Se9Q
<form action="" method="GET" name="form1" id="form1">
<div id="custom-search-input">
<div class="adress-div">
<input type="text" id="ok" name="domain" maxlenght="30" class="adress" pattern="(.{1,})?([.]{1})?.+[.]{1}.+" placeholder="np. www.page.com" title="Enter URL adress." autocomplete="off" required/>
<br>
<input type="submit" class="button2" value="Check!">
</div>
</div>
</form>
<?php
error_reporting(0);
if(isset($_GET['domain'])){
$domain = $_GET['domain'];
$godaddycheck = 'https://in.godaddy.com/domains/searchresults.aspx?checkAvail=1&tmskey=&domainToCheck='.$domain.'';
$namecomcheck = 'https://www.name.com/domain/search/'.$domain.'';
$registercomcheck = 'http://www.register.co, m/domain/search/wizard.rcmx?searchDomainName='.$domain.'&searchPath=Default&searchTlds=';
if ( gethostbyname($domain) != $domain ) {
echo "<br><br><h1 style='color: #e30000;'><b>$domain</b> not available.</h1>";
}
else {
echo "<br><br><h1 style='color: #00e339;'><b>$domain</b> available.</h1><h2>
</h2>";
}
}
?>
This is not possible doing only with PHP.
You will need to do that with JavaScript. Therefore you need to
listen on an input change for your <input>field
Send the value of the input field with AJAX (https://developer.mozilla.org/en-US/docs/Web/Guide/AJAX/Getting_Started) to a PHP script, which then validates the domain
Fetch the response and display it to the user
But there are a lot of tutorials out there, how to do that. For example: https://www.w3schools.com/php/php_ajax_php.asp
I have created a search query to filter records from the database. Whenever I enter the value I want to filter for eg the email as a criteria and click on search, it retrieves the record from the database, if I click on search again instead of adding the new search result it repopulate the list with the new records and keeping the old record in view.
editted
this is adminList initialization
List<Admin> adminList = new ArrayList<Admin>();
this is the query I am using to search
#SuppressWarnings("unchecked")
public List<Admin> getAllAdmins(String singleAdmin) {
try{
String query = "SELECT DISTINCT e.* FROM admin e WHERE e.email like '%"+ singleAdmin +"%'";
List<Object[]> adminObjects = fetchAll(query);
for(Object[] adminObject: adminObjects) {
Admin adminIndividual = new Admin();
Integer id = ((Integer) adminObject[0]);
String email = (String) adminObject[1];
String name = (String) adminObject[2];
adminIndividual.setId(id);
adminIndividual.setEmail(email);
adminIndividual.setName(name);
adminList.add(adminIndividual);
}
System.out.println("database values for admin>>>>> "+adminList);
return adminList;
}catch(Exception e){
e.printStackTrace();
return null;
}
}
this is the snippet of code in my .jsp file that send the data to the controller to make a search for the query criteria
<form method="post" action="searchAdmin">
<p><label for="name">Admin Email</label>
<input class="form-control" type='text' name='searchName' id='searchName'/>
<input class="btn btn-success" type='submit' value='RETRIEVE'/>
</p>
this is how I am populating the list that gets the values whenever a new search is made
<c:forEach items="${adminList}" var="admin">
<p>
<label for="name">FULLNAME</label>
<input type="text" name="name" placeholder="" value="${admin.name}" readonly/>
</p>
<p>
<label for="email">Email</label>
<input type="text" name="email" placeholder="" value="${admin.email}" readonly/>
</p>
</c:forEach>
you can see the fullname repeating twice and if I enter an email again to click on search, it doubles to three retaining the two previous records. Please how do I tackle this issue whenever I try to search, as the page refreshes let is populates the search query with out repeating with the previous search query. Kindly assist!
Weird this one.
On my .NET MVC 4 project I've added a file on App_Code who contains this method:
#helper CheckBox(string name, bool isChecked = false, string className = "") {
<div class="checkboxHolder">
<input id="#name" name="#name" type="hidden" value="#isChecked") />
<i class="#className checkboxBts fa #((isChecked) ? "fa-check-square-o" : "fa-square-o")" data-checkbox-associated="#name"></i>
</div>
}
I'm using it to style checkboxes using font-awesome, so my app checkboxes are made of an input type hidden who stores a boolean value and an icon to give feedback to users.
Weird thing is, on executing when isChecked == false, the hidden returned by this method is like:
<input id="myCheckboxId" name="myCheckboxId" type="hidden" />
There is no value at all, when I try to save it to the model an exception is thrown saying that model cannot be saved.
I've fixed it changing the method to use:
<input id="#name" name="#name" type="hidden" #((isChecked) ? "value=true" : "value=false") />
Which is working fine. However, I wonder if anyone know what could be happening on the original output.
Thank you all.
It's not entirely a duplicate, but this is answered in Why is my hidden input writing: value=“value” instead of true/false?:
if you have:
<input name="somefield" type="hidden" someprop="#(SomeBooleanExpression)"/>
[and #SomeBooleanExpression] is false it is omitted completely:
<input name="somefield" type="hidden"/>
To get around this, consider .ToString()
So, use:
<input id="#name" name="#name" type="hidden" value="value="#(isChecked.ToString())" />
A list is passed to the display:table. In the table i need to have a checkbox column to select/deselect any transactions that are selected. How do i associate the checked item with the transaction. Also i need to pass this checked transaction to a java script.
Thanks
Jsp code:
<display:column title="<input type='checkbox' name='selectall' onClick='selectAll()' />" media="html">
<input type="checkbox" name="selectBox" class="selectableCheckbox" id="selectBox" value="${sample.txniD}"></>
</display:column>
<display:column property="txniD" sortable="true" scope="all" title="Transaction ID %>" />
Try alerting the value of the checkbox, alert(checkboxArray[i].value);, not toString.
Im building a registration form and planning to use dojox.form.PasswordValidation to verify if the inputted passwords are the same. Is there a way to use dojox.form.PasswordValidation programatically? If i do this:
<div id="sample">
<input type="password" pwType="new" />
<input type="password" pwType="verify" />
</div>
<script>
var a = new dojox.form.PasswordValidation({}, "sample");
</script>
The above code works as expected, but I want to strip-off those "pwType" tags and create a pure HTML tags only. If I do that, where should I put "pwType"?
P.S. I'm using Dojo 1.6
Unfortunately it looks like this widget is not really up-to-date with the recent changes where dojo tries to move all the invalid html attributes into the valid data-* attributes. When looking at the postCreate method of that widget it has this code in the middle of it:
dojo.forEach(["old","new","verify"], function(i){
widgets.push(dojo.query("input[pwType=" + i + "]",
this.containerNode)[0]);
}, this);
And just afterwards it makes sure that it found the necessary inputs, otherwise it will throw an error.
So if you want to use something other than the pwType attributes, then you will probably have to overwrite the postCreate method of this widget to query something else, for example:
dojo.query("input[data-dojo-password-type=" + i + "]")
and then you can specify the values in data-dojo-password-type instead of pwType like this:
<div id="sample">
<input type="password" data-dojo-password-type="new" />
<input type="password" data-dojo-password-type="verify" />
</div>
what about something like :
var theDiv = dojo.create("div", {id: "sample"}),
theNewPass = dojo.create("input", {type: "password", pwType: "new"}, theDiv, "last"),
theVerifPass = dojo.create("input", {type: "password", pwType: "verify"}, theDiv, "last"),
a = new dojox.form.PasswordValidation({}, "sample")
;