I have dataGrid and LinkButton with javascript,
how to get ID for MessageSend function?
<ItemTemplate>
<asp:ImageButton ID="MessageButton" runat="server" OnClientClick="javascript:void(MessageSend(SomeID))" ImageUrl="Header.gif"/>
</ItemTemplate>
<asp:BoundColumn Visible="True" DataField="SomeID" ReadOnly="True" HeaderText="ID"></asp:BoundColumn>
do this way
function MessageSend(sender) {
// do whatever with the input
}
and in the OnClientClick use javascript:MessageSend(this);
The result is you get the sender element in your routine.
Related
Using Grails 3.0.9
Making a Clear Form/session button for the filter class. however nothing i do works.
The button is just stuck there, nothing happens
Any help will be appreciated
SupplyController
def index(Integer max) {
params.max = Math.min(max ?: 10, 100)
if (params.name)
session.name = params.name
else if (request.method != "POST")
params.name = session.name
else
session.name = null
def criteria = Supply.createCriteria()
def query = {
and{
if (params.name) {
like ("name", '%' + params.name + '%')
}
}
}
def results = criteria.list(params, query)
respond results, model:[supplyCount: results.getTotalCount()]
}
G:field type of code
<div class="filter">
<h3>Filter:</h3>
<g:form action="index" method="post" >
<label for='name'>Name:</label>
<input type="text" id="name" name="name" value="${session.name}"/><br/>
<span class="button">
<g:submitButton name="index" class="index" value="Apply Filter" /></span>
<g:field type="reset" name="myReset" value="Reset" />
</g:form>
</div>
HTML tag type
<div class="filter">
<h3>Filter:</h3>
<g:form action="index" method="post" >
<label for='name'>Name:</label>
<input type="text" id="name" name="name" value="${session.name}"/><br/>
<span class="button">
<g:submitButton name="index" class="index" value="Apply Filter" /></span>
<input type='reset' value='Reset' />
</g:form>
</div>
An HTML form reset button for a form rests the form to the initial state. In this case back to the values it had when the form loaded. A HTML form reset button does not CLEAR the form or CLEAR the session.
wondering why you are using session for where typicalls form params should be used? In order to clear HTML session you would need to trigger a call back to the originating controller just like you would to post but when it receives via this call. It does a session.invalidate() and then renders same view again. You should try to stick with params for forms. The fact that you have the session information already really no need to post it via a form. Your controller receiving the form would be aware of that same session value.
You could easily create a jquery functionality that you do with a button that triggers and a resetform. jQuery/Javascript function to clear all the fields of a form
Or if that does not work you could try for example in your case:
<g:form ..>
..
<button onClick="clearName();" name="clickme">
</g:form>
<g:javascript>
function clearName() {
$('#name').val();
}
</g:javascript>
I have the app working using Radio buttons e.g.
#using (Html.BeginForm("SetCulture", "Home"))
{
<input type="radio" name="culture" id="en-us" value="en-us" class="culture" /> English
<input type="radio" name="culture" id="tr" value="tr" class="culture" /> Türk
}
but when i use input of image type it does not send the wanted VALUE
#using (Html.BeginForm("SetCulture", "Home"))
{
<input type="image" src="~/Content/Images/en.png" name="culture" id="en-us" value="en-us" class="culture" />
<input type="image" src="~/Content/Images/tr.png" name="culture" id="tr" value="tr" class="culture" />
}
jQuery code:
$(".culture").click(function () {
$(this).parents("form").submit(); // post form
});
HomeController Code:
public ActionResult SetCulture(string culture){
// action code here
}
I see no reason why the images wouldn't work but for some reason it happens. Any ideas?
Thank you so much
In the first code block (using <input type="radio" .. />), you form will only post back one value for culture (the value of the selected radio button).
In the second code block (using <input type="image" .. />) your form will post back the values of both inputs, so your form data is culture=en-US&culture=tr
The DefaultModelBinder will bind the first value and ignore the second value so the value of culture in the POST method will always be "en-US" irrespective of which image you click.
One option would be to disable the other input (disabled inputs do not post back a value, for example
$(".culture").click(function () {
$(this).siblings().prop('disabled', true); // disable the other input
$(this).parents("form").submit(); // post form
});
Another option for handling this is to use <img> tags in conjunction with a hidden input for the culture value
<input type="hidden" name="culture" id="culture"/>
<img src="~/Content/Images/en.png" data-culture="en-US" class="culture" />
<img src="~/Content/Images/tr.png" data-culture="tr" class="culture" />
$('.culture').click(function () {
$('#culture').val($(this).data('culture')); // update the hidden input
$('form').submit();
})
How do I use a struts submit button to submit the specific id of an object in an iterated list?
<s:form action="actionDeleteBooking">
<s:iterator var = "bookingList" value="bookings">
<s:submit label="delete booking" value = "cancel booking" theme = "simple" id="bookingid" />
</s:iterator>
</s:form>
I can do if for a radio button:
<s:form action="actionConfirmBooking">
<s:iterator var = "pathList" value="results">
<s:iterator var = "flightList" value="pathList">
<s:radio name="flightSelected" list="flightList" listKey = "flightid" id = "flightid" value = "flightid"/>
</s:iterator>
</s:iterator>
<s:submit label="Submit" />
</s:form>
if what you are trying to achieve is to have a submit button for each "row", submitting one value, then use multiple forms and an hidden field:
<s:iterator var = "bookingList" value="bookings">
<s:form action="actionDeleteBooking">
<s:hidden name="selectedItem" value="%{bookingid}" />
<s:submit label="delete booking" value="cancel booking" theme="simple" />
</s:form>
</s:iterator>
Otherwise use an <s:a />, or set a field with JavaScript, or describe better what you want.
You can use checkbox tag for the items you want to delete. You should be able to do this because you have already used similar form with s:radio.
<s:form action="actionDeleteBooking">
<s:iterator var = "bookingList" value="bookings">
<s:checkbox name="bookingids" label="bookingid" />
</s:iterator>
<s:submit label="delete bookings" value = "cancel booking" theme = "simple"/>
</s:form>
Quiz project, a question has a radiobuttonlist with either 2 items(T/F) or 4 items (a,b,c,d)
number of questions varies. Panel is used to show only one question at a time (show/hide).
after answering all questions user clicks on submit button and all answers should be saved in database. In code behind selecteditem is always null and value is always empty string.
<asp:DataList ID="dtQuestion" runat="server" RepeatDirection="Vertical" OnItemDataBound="FormatDataListRow" >
<ItemTemplate>
<asp:Panel id="panel" runat="server" BorderColor="#536895" BorderStyle="Solid" BorderWidth="1" style="display: none;" EnableViewState="true">
<asp:Label id="lblQuestionDesc" runat="server" Text="" ></asp:Label>
<asp:RadioButtonList id="rbl" runat="server" EnableViewState="true" > </asp:RadioButtonList>
</asp:Panel>
</ItemTemplate>
</asp:DataList>
on submit click. I call a function that search the page for RBL I am able to see their correct ID's and list items but nothing is selected.
string id;
if (c.GetType().ToString().Equals("System.Web.UI.WebControls.RadioButtonList"))
{
if (c.ID != "rbl")
{
id = c.ID;
al.Add(id + "," + ((RadioButtonList)c).SelectedItem.Value); //SelectedValue); //
}
}
It seems that you're populating the RadioButtonList on the page load -
If so - make sure you surround your population of the RadioButtonList with an
If/Then/Postback block:
if not Page.IsPostBack then
' populate your RBL
end if
eg:
if (!IsPostBack)
{
loadradiobuttonlist();
}
Try accessing the submitted value like this:
this.Request.Form[((RadioButtonList)c).UniqueID]
During debugging you can always check what values you've got in this.Request.Form collection.
I have this following piece of code:
<h:form id = "fm-rewDet">
<ui:repeat var="review" value="#{controller.reviewStatusList}">
<h:commandLink value = "TestLink" action = "#{controller.rewDetail}" />
</ui:repeat>
</h:form>
The controller contains the following:
public void rewDetail(){
System.out.println("I'M HERE");
}
The following HTML code is rendered:
<form id="fm-rewDet" enctype="application/x-www-form-urlencoded" action="/project/overview.xhtml" method="post" name="fm-rewDet">
<a onclick="mojarra.jsfcljs(document.getElementById('fm-rewDet'),{'fm-rewDet:j_idt224:0:j_idt255':'fm-rewDet:j_idt224:0:j_idt255'},'');return false" href="#">TestLink</a>
//...
</form>
This simple example does not work at all. When the link is pressed some action takes place but weirdly the I'M HERE message fails to appear.
What is the cause of this?