I currently have a databound dropdown list on my ASP.Net C# 2.0 website that has around 400 items in it. I want to replace it with something similar like the textbox in google search where you enter letter and only the entries starting with those letters pop up
what is a good way of implementing it? Are there controls that already exists that anybody can suggest?
One way to do this using HTML5 (for small datasets of course) is datalist:
<input list="users" name="users">
<datalist id="users">
<option value="Alice">
<option value="Bob">
<option value="Chuck">
<option value="Chris">
<option value="Duke">
<option value="Emily">
</datalist>
For larger datasets AJAX is a better way to go.
Take a look at http://docs.jquery.com/Plugins/Autocomplete
Also here is a tutorial for use with ASP.Net
check complete.ly too
http://complete-ly.appspot.com/
it has no dependencies and weights very little.
If these are known enrties, you can use JQuery, and on the OnUpdate event:
if it's a long list, make Ajax Request to your webserver, retrieve the best option
if it's a short list, you can load all the options to the page, and offer the optional texts without making a server request.
Checkout the JQuery library for implementations on how to display the suggestion.
There's an AutoComplete extender as past of the AJAX Control Toolkit for ASP.NET. There are plenty of different options that you can set for client caching, delay interval. Just point it at a web service or page method and away you go.
TextBoxValueToDropDownList
function AddNames(text) {
if (document.myForm.insertText.value == "") {
document.getElementById("insertText").style.border = "1px solid red";
return false;
}
else {
var option = document.createElement("OPTION");
option.text = text.value;
option.value = text.value;
document.getElementById("dropDownList").options.add(option);
document.myForm.insertText.value = "";
document.getElementById("insertText").style.border = "1px solid green";
}
}
<form name="myForm">
<table>
<tr>
<td>
<input type="text" name="insertText" id="insertText" /></td>
<td></td>
<td>
<select name="dropDown" id="dropDownList">
</select>
</td>
</tr>
<tr>
<td>
<input type="button" value="Insert" id="button" onclick="AddNames(insertText);" /></td>
</tr>
</table>
</form>
Related
As part of a test scrip I have to redirect to a 3rd party hosted payment page. However, when I try and find the input box elements it errors slightly differently depending on which call I try:
$driver->find_element_by_id("card.billingAddress.houseNumberOrName")->clear
returns "Element is not currently visible and so may not be interacted with"
$driver->find_element_by_xpath('//input[#id="card.billingAddress.houseNumberOrName"')->clear
returns "SyntaxError: The expression is not a legal expression."
The source of the section I am searching is:
<tr>
<td colspan="2"><div class="fieldSubHeader">Billing Address</div>
</td>
</tr>
<tr>
<td><div id="idAddress1_card" style="display:inline">Address 1</div>
<div id="idHouseNumberOrName_card" style="display:none">House Number/Name
</div</td>
<td><div class="fieldDiv" id="idDivAddress1_card">
<input type="text" class="inputField" id="card.billingAddress.houseNumberOrName" name="card.billingAddress.houseNumberOrName" value="" size="15" maxlength="40" />
</div></td>
</tr>
Is it the . in the ID that is causing the issue?
(I have checked the computed CSS and it is not hidden!)
Many thanks
You are missing the closing ]. Replace:
'//input[#id="card.billingAddress.houseNumberOrName"'
with:
'//input[#id="card.billingAddress.houseNumberOrName"]'
HERE ^
Note that you might simplify it by switching directly to the find_element_by_id() method.
I have a form which the data is being submitted to a table.
Using the column 'month_date_show' I would like to auto fill the form
if that date exist in the column in the table, since it will only be submit once a month.
If the date does exist in the table then the user will be able to edit those results, if it does not exist
then no need to auto fill the user will submit new results for that month.
Not sure if this is something that will have to use ajax or java script to make it happen.
Right now I hard coded the values in the form , but i would like to make it dynamic.
<cfquery datasource ="intranet" name="GetSummary">
SELECT * from cse_result_summary
</cfquery>
<form method="post" name="myform" action="cse_execoffice_datepicker_test.cfm" onsubmit="return validateForm()">
<table >
<tr>
<td>
<input type="text" id="dpMonthYear" NAME="month_date_show" value="9/2014" style="width:80px;" />
</td>
<td>
<img alt="Month/Year Picker" onclick="showCalendarControl('dpMonthYear');"
src="pictures/datepicker.gif" />
</td>
</tr>
</table>
<table >
<tbody>
<tr>
<td> Rising Star Award Winner:</td>
<td><input type="text" name="risingstar" size="50" class="get_branches_departments_displaynum" value="john"></td>
</tr>
<tr>
<td>Department Average:</td>
<td><input type="text" name="risingstar_ave" size="8" class="get_branches_departments_displaynum" value="5"></td>
</tr>
<tr>
<td> Rising Star Award Winner runner-up:</td>
<td><input type="text" name="risingstar_runner" size="50" class="get_branches_departments_displaynum" value="joe"></td>
</tr>
</tbody>
</table>
<p><input type="submit" name="Submit" value="Submit"></p>
</form>
Well, if you are actually storing the month and year of the forms submitted, and assuming that the users are submitting form for the current month and current year (i.e. it is September 2014 now and the users would be submitting form for 09/2014 but not submitting form for any other form, ex. 08/2014), then at the time when a user gets to your page, you already know whether a new form is needed by searching against the database.
You can then populate the form accordingly.
It depends. If you don't care if the user refreshes the page, just submit the form onChange, run the query to select information for that date
SELECT winner, average, runup
FROM tablename
WHERE datecol = <cfqueryparam type=<whatevertypeappropriate> value="#val_name#">
In your form just have the value field value dynamically assigned.
<input type="text" name="winner" value="#queryname.winner#">
If you don't want them to have to resubmit the form, I think there'll have to be some kind of binding.
I'm making a calendar where each day has a radio button that allows you to select it. I want users to only be able to select one day. The issue I'm having is I've made the calendar as a table so each <td> has the following:
<td>
<form>
Mon 18
<input type="radio" name="day" value="mon18" />
</form>
</td>
So as all the radio buttons aren't contained in one form element, the normal behaviour that makes the selection mutually exclusive isn't occurring. If I create 1 form element around all my mark up then the table will be contained in it, would this be semantically correct?
Is there a semantically correct solution to my problem? I guess I could do it with javascript and server side validation.
It is perfectly semantically correct to have the form enclosing your table, that's actually the only sensible way to build your radiobutton-based calendar with mutually exclusive selection!
The following code does validate:
<form>
<table>
<tr>
<td><input type="radio" name="day" value="1"></td>
<td><input type="radio" name="day" value="2"></td>
...
</tr>
</table>
</form>
I've been messing with this for far too long, and managed to get IE8 working, but IE7 has me stumped.
I've got a table, and for each column, I am trying to extract a number of divs. I am only extracting divs which match specific selectors, not all divs in the column.
My original jquery selector was
jQuery('div.a1, div.a3, div.a4, div.a7','table#a'+tableId+' td:nth-child('+columnNum+')').each(function(){
alert(jQuery(this).attr('id'));
});
This worked great in FF, but didn't trigger the .each function at all in IE.
After messing around for a bit, I got to
jQuery('td:nth-child('+columnNum+') > div.a1, td:nth-child('+columnNum+') > div.a3, td:nth-child('+columnNum+') > div.a4,td:nth-child('+columnNum+') > div.a7', table#a+'tableId).each(function(){
alert(jQuery(this.attr('id'));
});
Not so nice, but works in IE8.
I had tried all sorts of combinations using .eq(+'columnNum+') but nothing else was working.
Now I go and test in IE7, and again the .each isn't being triggered.
What is the nicest way (and cross-browser compatible) to work with this sort of .each element?
--------------addition--------------
After further testing and playing around with suggestions from DrJ and bdukes, I've found that the table#'+tableId breaks the function in both IE7&8.
I've gone back to my original code
jQuery('div.a1, div.a3, div.a4, div.a7','table#a'+tableId+' td:nth-child('+columnNum+')').each(function(){
alert(jQuery(this).attr('id'));
});
as that seems to me the most efficient.
If I remove 'table#a'+tableId, i get the correct response in all browsers, except that it is adding up the results from all tables, and I need to be able to get only the results from one table at a time.
I have also tried 'table#a'+tableId+'>td:nth-child('+columnNum+')').each, but that doesn't work either.
The first function i've used works perfectly in firefox.
----------------the html being selected---------------------------
The tables are being created dynamically in javascript so I can't really copy and past it, but here is what the output looks like. It ends up looking kinda like a gantt chart on a table.
<table id="a1">
<tr>
<th colspan="5">
Group Name
</th>
</tr>
<tr class="rowId1" >
<td>
<div class="a1" id="a43" style="margin-left:13px; width:60px" ></div>
</td>
<td>
</td>
<td>
<div class="a3" id="a93" style="margin-left:4px; width: 80px" ></div>
<div class="a2" id="a94" style="margin-left:4px; width: 30px" ></div>
</td>
<td>
<div class="a1" id="a24" style="margin-left: 15px; width: 65px;" ></div>
</td>
<td>
</td>
</tr>
</tr>
<tr class="rowId1" >
<td>
<div class="a7" id="a24" style="margin-left:10px; width:60px" ></div>
</td>
<td>
<div class="a2" id="a15" style="margin-left:14px; width: 22px" ></div>
</td>
<td>
;
<div class="a2" id="a105" style="margin-left: 8px; width: 50px" ></div>
</td>
<td>
</td>
<td>
<div class="a4" id="a102" style="margin-left: 5px; width: 45px;" ></div>
</td>
</tr>
</table>
It turns out this was an issue with IE failing when two different elements have the same ID. Apparently this breaks the .each function.
I had two tables
table.notes#a1 & table.inputs#a1
The .each function should have gone through each table but instead found neither.
jQuery also wouldn't run in ie with
jQuery('div.a1, div.a3, div.a4, div.a7','table.inputs#a'+tableId+' td:nth-child('+columnNum+')').each(function(){
alert(jQuery(this).attr('id'));
});
which it should have done, as I am them pointing directly to a specific table even if the id is not unique.
I'm using id's retrieved from the database for the id, and IE doesn't like id's that start with numbers, so I just added an 'a' to the beginning of the id.
However, it apparently doesn't like that either, so now I'm adding the first letter of the class and then the '1' or whatever the id number is.
This solves the issue.
I'm currently trying to use Zend_Form, and it's decorators mechanism, in order to output some well formated HTML, but I don't manage to have the wanted output.
Concretely, I have a radio button form element (Zend_Form_Element_Radio), with a multiple option registred in it, like this:
$codeHolder = new Zend_Form_Element_Radio('radiobuttons');
$codeHolder->setLabel('Title');
$codeHolder->addMultiOptions(array( 1 => 'Label1',
2 => 'Label2',
3 => 'Label3'));
$codeHolder->setValue('depart');
Here is the wanted HTML output:
`<tr>
<td><input type="radio" name="label1[radiobuttons]" id="id1" value="1" /></td>
<td><input type="radio" name="label1[radiobuttons]" id="id2" value="2" /></td>
<td><input type="radio" name="label1[radiobuttons]" id="id3" value="3" /><</td>
</tr>`
I have turned in many ways the problem, but I don't see any solution. Any help will be appreciated !
Solution was to use a personalised view helper to render the right HTML markup.
This article, about Zend_Form and helpers has really helped. A must-read !