I have an AJAX call that adds data to my ColdFusion database.
<!---Script to add dashboard link --->
<cfoutput>
<script>
$(function(){
//Add a new note to a link
$("##add_dashboard_links").submit(function(){
// prevent native form submission here
$.ajax({
type: "POST",
data: $('##add_dashboard_links').serialize(),
url: "actionpages/add_dashboard_link.cfm",
beforeSend: function(){
$('.loader').show();
},
complete: function(){
$('.loader').hide(3000);
},
success: function() {
$("##noteDiv").load( 'templates/dashboard_notes.cfm?techID=#techID#' );
$("##addNoteResponse").html('');
$("##link_description").val('');
$("##link_url").val('');
$("##notes").val('');
$("##addNoteResponse").append( "Link successfully added." );
}
});
return false;
});
});
</script>
</cfoutput>
I also have a CFDIV that binds to some other content
<!---Dashboard Links --->
<div id="noteDiv" bind="url:templates/dashboard_notes.cfm">
</div>
Here is my modal code located on my template page that contains the form that this AJAX script references (This plugin is found here https://github.com/kylefox/jquery-modal):
<!--- Link to open the modal to add a new dasboard link --->
<div id="DashboardLinks" style="display:none;">
<h3>Add a new dashboard link:</h3>
<form id="add_dashboard_links">
<table width="100%" id="dashboard_table" border="0" cellpadding="5">
<tr>
<td colspan="3"></td>
</tr>
<tr>
<td>Link Description:</td>
<td colspan="2"><input type="text" name="link_description" id="link_description" required="yes" message="Please enter the Link Description"/></td>
</tr>
<tr>
<td>Link URL:</td>
<td colspan="2"><input type="text" name="link_url" id="link_url" required="yes" validate="url" message="Please enter the Link URL with http:// -or- https://"/></td>
</tr>
<tr>
<td>Link Notes:</td>
<td colspan="2"><textarea id="notes" name="notes" cols="" rows=""> </textarea></td>
</tr>
<tr>
<td colspan="3"><input type="submit" name="button" id="button" value="Add Link" />
<input type="hidden" name="link_hidden" value="1"><br />
<div class="loader"><img class="loading-image" src="images/loading.gif" /></div>
<div class="response" id="addNoteResponse"></div>
</td>
</tr>
</table>
</form>
</div>
Is there a way to refresh this CFDIV tag once I recieve the AJAX SUCCESS?
Thanks.
Don't use cfdiv (or any other ColdFusion UI functionality). Since you are already using jQuery, stick with that. Use a plain old HTML <div> and keep the same id.
<div id="noteDiv" bind="url:templates/dashboard_notes.cfm"></div>
Then, in your AJAX call, add this to the success block
$("#noteDiv").load( 'templates/dashboard_notes.cfm' );
You will also need to add that line elsewhere to get the content loaded initially.
Related
Responseenter image description hereI have a kendo grid displaying ID,NID,SID(Student table) and some other fields.Now when i want to add new Student the NID field must me a dropdownlist populating the values from the database. How can we do this. What should be in the data-source . I wrote a query to get the NID. but how would i use it. Or is this wrong
Thanks
<div>
<table>
<tr>
<td>
<div>
<label for="ID">ID</label>
</div>
<div data-container-for="data.ID">
<input id="id" data-bind="value: data.ID" style="width: 250px;" name="ID" type="text" />
</div>
</td>
</tr>
<tr>
<td>
<div>
<label for="NID" id="lcid">NID</label>
</div>
<div>
<input id="cid" />
</div>
</td>
<td>
</td>
</tr>
</table>
</div>
Service:
$(document).ready(function () {
$("#cid").kendoDropDownList({
dataTextField: "NID",
dataValueField: "NID",
dataSource: {
transport: {
read: {
dataType: "jsonp",
url: "/Services/getNID",
}
}
}
});
});
<tr style="background: #D0CDCD;">
<td colspan='2'>
<input type="text" name="mytext1[]">
</td>
<td></td>
<td colspan='2' style="text-align:right;">
<input type="text" name="mytext2[]" id="txt1" onkeyup="sum();">
</td>
</tr>
This is my html code to add dynamic textboxes.
JS Script is follows
<script type="text/javascript">
$(document).ready(function() {
var max_fields= 3;
var x = 1;
$('a').click(function() {
if(x < max_fields){
x++;
$('#myTable #row').append('<tr class="child"><td class="child" colspan="2"><input type="text" name="mytext1[]"></td><td></td><td colspan="2" style="text-align:right;"><input type="text" name="mytext2[]"></td></tr>');
}
});
});
</script>
My problem is that I need to store the dynamically added textbox values to a variable so that I can perform some mathematical operations in that. I don't know how to achieve this. Please help me.
I got the result. I make use of javascript and jQuery
<tr style="background: #D0CDCD;">
<td colspan='2'><input type="text" name="mytext1[]"></td>
<td></td>
<td colspan='2' style="text-align:right;">
<input type="text" class="value_field" name="mytext2[]" >
</td>
</tr>
Function to append
<script type="text/javascript">
$(document).ready(function() {
$('a').click(function() {
$('#myTable #row').append('<tr class="child"><td class="child" colspan="2"><input type="text" name="mytext1[]"></td><td></td><td colspan="2" style="text-align:right;"><input type="text" name="mytext2[]" class="value_field"></td></tr>');
$("input.value_field").blur(function(){
check_value();
});
});
});
$("input.value_field").blur(function(){
check_value();
});
I have a form that submits just fine in FF, IE 8, IE 9, chrome.
In safari (windows), it submits but my model is empty. This behavior is only on my dev and prod site, not local development. Local development works normal. What am i doing wrong here?
Form:
<form action="/NetSite/Applications/ElectronicFileTransfer" id="TransfersSearchForm" method="post">
<table class="siteTable">
<tbody>
<tr>
<th style="width: 20%;">FICE</th>
<td style="width: 80%;"><input id="Criteria_Fice" maxlength="6" name="Criteria.Fice" size="6" type="text" value="" /></td>
</tr>
<tr>
<th>Source Email</th>
<td><input id="Criteria_SourceEmail" maxlength="40" name="Criteria.SourceEmail" size="25" type="text" value="" /></td>
</tr>
<tr>
<th>Target Email</th>
<td><input id="Criteria_TargetEmail" maxlength="100" name="Criteria.TargetEmail" size="25" type="text" value="" /></td>
</tr>
<tr>
<th>Upload From Date</th>
<td>
<input class="datePicker" data-val="true" data-val-date="Invalid date specified. Date should be like MM/DD/YYYY." id="Criteria_FromDate" maxlength="12" name="Criteria.FromDate" size="12" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Criteria.FromDate" data-valmsg-replace="true"></span>
</td>
</tr>
<tr>
<th>Upload To Date</th>
<td>
<input class="datePicker" data-val="true" data-val-date="Invalid date specified. Date should be like MM/DD/YYYY." id="Criteria_ToDate" maxlength="12" name="Criteria.ToDate" size="12" type="text" value="" />
<span class="field-validation-valid" data-valmsg-for="Criteria.ToDate" data-valmsg-replace="true"></span>
</td>
</tr>
<tr>
<th class="empty"></th>
<td>
<button type="submit" title="Search" id="SubmitButton" class="gradientbutton gradientsmall gradientorange">Search</button>
<button type="button" title="Clear" id="ClearButton" class="gradientbutton gradientsmall gradientorange">Reset</button>
</td>
</tr>
</tbody>
</table>
</form>
JS submit method called by the event:
searchFormSubmit: function ($form, currentForm) {
if ($form.valid()) {
var $button = $("#" + FileTransferHome._enum.SubmitButton);
var $searchResults = $("#" + FileTransferHome._enum.SearchResultsDivId);
jMessage("Processing request...", $button, true, false);
$.ajax({
cache: false,
url: currentForm.action,
type: currentForm.method,
data: $form.serialize(),
error: function (xhr, ajaxOptions, thrownError) {
jMessageHide();
$searchResults.html(xhr.responseText).addClass(JSGlobalVars.MessageBoxError).fadeIn('slow');
},
success: function (result) {
jMessageHide();
$searchResults.removeClass(JSGlobalVars.MessageBoxError).html(result).fadeIn('slow');
location.hash = "SEARCHRESULTS";
}
});
}
}
Action:
I have an else block in there that i have put in just to test this case and it executes rather than the main block.
[HttpPost]
public ActionResult Index(ElectronicFileTransferHomeViewModel model)
{
... actions...
}
This in as internal app and behind windows login. Safari has a non issue with with windows authentication.
A work around that seems to be working for us (although not ideal) is to put Safari in Private browsing mode.
I'm trying to put a button into grid. In order to achieve that I wanted to use rowTemplates. However I have a problem with geting and item id and put it into action parameter.
So far I tried these constructinos
<script id="rowTemplate" type="text/x-kendo-tmpl">
<tr>
<td>
<form action="/Home/EditProduct/?id="+ "#=Id#" class="addEditButton" method="post">
<submit type="button" value="Edytuj"/>
</form>
</td>
</tr>
</script>
<script id="rowTemplate" type="text/x-kendo-tmpl">
<tr>
<td>
<form action="/Home/EditProduct/?id="+ ${ Id } class="addEditButton" method="post">
<submit type="button" value="Edytuj"/>
</form>
</td>
</tr>
</script>
<script id="rowTemplate" type="text/x-kendo-tmpl">
<tr>
<td>
<form action="/Home/EditProduct/?id=${ Id }" class="addEditButton" method="post">
<submit type="button" value="Edytuj"/>
</form>
</td>
</tr>
</script>
<script id="rowTemplate" type="text/x-kendo-tmpl">
<tr>
<td>
<form action="/Home/EditProduct/?id=${ Id } class="addEditButton" method="post">
<submit type="button" value="Edytuj"/>
</form>
</td>
</tr>
</script>
However non of this method can successfully retrieve value of id parameter from object bounded to row. Is it possible to somehow pass value of id into action ??
I think this will answer your question.
http://andregelderblom.wordpress.com/2012/02/27/pass-kendoui-datagrid-variable-to-template-that-uses-zend-url/
Below is example html, script and php to submit and reload two forms via jquery ajax. In the real application, the same forms will not be reloaded but a series of forms will be loaded after each is submitted.
In chrome, IE and safari; clicking submit results in the intended ajax request. The server responds as intended. Results (showing post variables for conformation) and new forms are loaded into the page as intended. Those new forms can then be submitted and all is good.
In firefox; everything works as intended until you try to submit the forms that were loaded via ajax. They will not submit. The original forms do work. It is only the ones added via ajax that don't submit.
I am guessing that this is an "event delegation" issue with the way firefox updates the DOM after the ajax. I have read the documentation at http://api.jquery.com/on/ and other places but I am at a loss...
Any help or suggestions would be greatly appreciated! My goal is to get this functional in the latest versions of chrome, IE, safari and firefox.
html page with script
<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<title>Example Ajax Form Submit</title>
<script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"></script>
</head>
<body>
<div id="results"></div>
<div id="forms">
<div>
<table width="100%" cellspacing="0" cellpadding="0" class="ui-widget">
<form>
<tr>
<td width="100"></td><td width="300"></td><td></td>
</tr>
<tr>
<td class=""colspan="3"><h1>Form 1</h1></td>
</tr>
<tr>
<td>Input 1A</td><td colspan="2"><input type="text" name="1A" /></td>
</tr>
<tr>
<td colspan="3"><input type="hidden" name="1B" value="Form 1 was submitted" /></td>
</tr>
<tr>
<td colspan="3"><button type="submit" >Click Me!</button><input type="submit" value="Submit Form 1" /></td>
</tr>
</form>
</table>
</div>
<div>
<table width="100%" cellspacing="0" cellpadding="0" class="ui-widget">
<form>
<tr>
<td width="100"></td><td width="300"></td><td></td>
</tr>
<tr>
<td class=""colspan="3"><h1>Form 2</h1></td>
</tr>
<tr>
<td>Input 2A</td><td colspan="2"><input type="text" name="2A" /></td>
</tr>
<tr>
<td colspan="3"><input type="hidden" name="2B" value="Form 2 was submitted" /></td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Submit Form 2" /></td>
</tr>
</form>
</table>
</div>
</div>
<script type="text/javascript">
$(document).ready(function(){
$("#forms").on("submit", "form", function(e) {
e.preventDefault();
$.ajax({
url: "testAjax.php",
type: "POST",
cache: false,
data: $(this).serializeArray(),
success: function(jsonData) {
htmlData = jQuery.parseJSON(jsonData);
$.each(htmlData, function(id, data){
$("#"+id).html(data);
});
},
error: function(jqXHR, textStatus, errorThrown){
$("#results").html("<p>Somthing went wrong!</p>");
}
});
});
});
</script>
</body>
</html>
testAjax.php
<?php
$htmlOutput['forms'] =
'<div>
<table width="100%" cellspacing="0" cellpadding="0" class="ui-widget">
<form id="login" method="post" enctype="multipart/form-data" target="_self" action="_self">
<tr>
<td width="100"></td><td width="300"></td><td></td>
</tr>
<tr>
<td class=""colspan="3"><h1>Form 1</h1></td>
</tr>
<tr>
<td>Input 1A</td><td colspan="2"><input type="text" name="1A" /></td>
</tr>
<tr>
<td colspan="3"><input type="hidden" name="1B" value="Form 1 was submitted" /></td>
</tr>
<tr>
<td colspan="3"><button type="submit" >Click Me!</button><input type="submit" value="Submit Form 1" /></td>
</tr>
</form>
</table>
</div>
<div>
<table width="100%" cellspacing="0" cellpadding="0" class="ui-widget">
<form>
<tr>
<td width="100"></td><td width="300"></td><td></td>
</tr>
<tr>
<td class=""colspan="3"><h1>Form 2</h1></td>
</tr>
<tr>
<td>Input 2A</td><td colspan="2"><input type="text" name="2A" /></td>
</tr>
<tr>
<td colspan="3"><input type="hidden" name="2B" value="Form 2 was submitted" /></td>
</tr>
<tr>
<td colspan="3"><input type="submit" value="Submit Form 2" /></td>
</tr>
</form>
</table>
</div>';
$htmlOutput['results'] =
'<p>Form 1:<br> 1A = ' . $_POST['1A'] . '<br>1B = ' . $_POST['1B'] . '</p>' .
'<p>Form 2:<br> 2A = ' . $_POST['2A'] . '<br>2B = ' . $_POST['2B'] . '</p>';
echo json_encode($htmlOutput);
?>
Open Firebug DOM inspector and verify that your form indeed loaded. I am pretty sure you are not allowed to nest form element directly under table element, and FF is likely simply dropping it.
In general issues like this one are always due to broken HTML. Verify that your HTML is correct. Verify that loaded DOM is what you expect it to be.
Here is how your HTML is being parsed. As expected form has been mangled.