I've created a table of dynamic controls which each row is a couple of (DropDownList and TextBox) then I've associated an event handler on each DropDownList selected change event so I can change on its TextBox as the code below shows :
DropDownList TypeDDL = new DropDownList();
TypeDDL.ID = "TypeDDL_" + rowN.ToString();
TypeDDL.Width = 120;
TypeDDL.Height = 20;
InitializeTypeDDL(TypeDDL);
TypeDDL.AutoPostBack = true;
TypeDDL.Attributes.Add("onchange", "javascript:handleFieldsDDLEvent(this);");
TextBox FieldsDDL = new TextBox();
FieldsDDL.ID = "FieldsDDL_" + rowN.ToString();
FieldsDDL.Width = 120;
FieldsDDL.Height = 20;
FieldsDDL.Attributes.Add("style", "float:right");
but the Javascript code of the event handler fires an exceptions telling:
function handleFieldsDDLEvent(e) {
var elementId = (e.target || e.srcElement).id;
var IdArray = elementId.Split('_');
var ControlId = "Control_"+IdArray[1].toString();
if (IdArray[1] != "") {
var FieldsDDL = document.getElementById("<%="+ControlId +".ClientID%>");
// error CS1026: ) expected
ValueTxtBx.style.display = "none";
}
}
In your javascript you have
var FieldsDDL = document.getElementById("<%="+ControlId +".ClientID%>");
The <%= ... %> parts are rendered on the server so it cannot be done this way in javascript.
Related
I'm trying to get a value from a GridView cell to change the source of an embed PDF. I execute a function when a button that is placed on each row of the GridView is clicked.
This is the code I have so far:
<script>
function changepdf(pdf) {
var value = document.getElementById('<%= GridView1.ClientID %>').rows[pdf.rowIndex].cells[3].innerText;
var file = document.getElementById('pdf');
file.src = 'pdf/catalogosh.pdf#page=' + value + '&#toolbar=0&#view=fit';
return false;
}
</script>
The Javascript function works fine when I write exactly the new source like this:
<script>
function changepdf(pdf) {
var file = document.getElementById('pdf');
file.src = 'pdf/catalogosh.pdf#page=4&#toolbar=0&#view=fit';
return false;
}
</script>
The main idea is to change the PDF page taking the value from de GridView.
Thanks in advance for any help.
I've just solved it. I'm pasting the code here for anyone that's trying to solve the same problem:
function changepdf(pdf) {
var row = pdf.parentNode.parentNode;
var rowIndex = row.rowIndex;
var value = document.getElementById('<%= GridView1.ClientID %>').rows[rowIndex].cells[2].innerText;
var file = document.getElementById('pdf');
file.src = 'pdf/catalogosh.pdf#page=' + value + '&#toolbar=0&#view=fit';
return false;
}
My problem was the rowIndex. The code was bad and I was getting the wrong value.
I added this two lines to get it well:
var row = pdf.parentNode.parentNode;
var rowIndex = row.rowIndex;
And then I got the cell value with this line:
var value = document.getElementById('<%= GridView1.ClientID %>').rows[rowIndex].cells[3].innerText;
New to sapui5, and I'm trying to make a change to an existing development and add another button to this UI.
Here is my coding, I am trying to add oAssetBtn2 to the UI, the other button already works??
Currently, I am getting the error:
AppController.js:2283 Custom code error: Error: adding element with duplicate id 'assetBtn-Custom2'
Error: Error: adding element with duplicate id 'assetBtn-Custom2'
ASSETCREATE = function() {
var oAssetBtn2 = sap.ui.getCore().byId('assetBtn-Custom2');
};
ASSETCREATE.prototype.CUSTOM_POST_EXIT = function(methodName, view,
controller,methodSignature, dialog) {
if (view == 'accountLineDetails') {
sap.ui.getCore().byId('CategoryListDetAS').setProperty('enabled',false);
this.accounting =
sap.ui.getCore().byId("accAssignment").getController().accounting;
var oFormModel = this.accounting.callMethod("_getFormModel");
var oModel = oFormModel.oData ;
jQuery.sap.require("sap.ui.commons.MessageBox");
var oBtnLayout =
sap.ui.getCore().byId(sap.ui.getCore().byId('saveBtn').getParent().getId());
var oAssetBtn = sap.ui.getCore().byId('assetBtn-Custom');
// Add the "Create Multiple Asset" button in the footer layout
jQuery.sap.require("sap.ui.commons.MessageBox");
var oBtnLayout2 =
sap.ui.getCore().byId(sap.ui.getCore().byId('cancelBtn').getParent().getId());
var oAssetBtn2 = sap.ui.getCore().byId('assetBtn-Custom2');
<%
data: lv_langu type sy-langu.
lv_langu = sy-langu.
%>
var lv_language = "" ;
var lv_text = "";
var lv_multiple_txt = "";
if( lv_language == "F" ){
lv_text = "Créer Immo";
lv_multiple_txt = "Créer Plusieurs Actifs";
}
else{
lv_text = "Create Asset";
lv_multiple_txt = "Create Multiple Assets";
}
var oAssetBtn2 = new sap.ui.commons.Button({
id : "assetBtn-Custom2",
text : lv_multiple_txt,
tooltip : Appcc.getText("Create many Assets")
});
if (!oAssetBtn) {
var oAssetBtn = new sap.ui.commons.Button({
id : "assetBtn-Custom",
text : lv_text,
tooltip : Appcc.getText("Creates an Asset")
});
thanks fellow coders!
View of the error in Chrome:
err
For adding a button to your app, you must bind it to your view or viewing page. How are you going to do this [Layout/view name].addContent([button name]);
in your case it will be
oBtnLayout2.addContent(oAssetBtn2);
I created a form dynamically with javascript. Now I have to add validations on the form (only mandatory validations) on click of the button which is also dynamically created. Now the issue I am facing is that whenever I try to add addEventListener on the button exactly after creating it, it is giving me error.
(
function init() {
console.log("div created");
// create a new div element
var newDiv = document.createElement("div");
newDiv.id = "registration_form";
var createForm = document.createElement("form");
newDiv.appendChild(createForm);
var heading = document.createElement("h2");
heading.innerHTML = "Registration Form";
createForm.appendChild(heading);
var linebreak = document.createElement('br');
createForm.appendChild(linebreak);
createElement(createForm, 'label','','','Name: ');
createElement(createForm, 'text', 'dname', '','');
createSpanTag(createForm,'nameError');
breakTag(createForm);breakTag(createForm);
createElement(createForm, 'label','','','Email: ');
createElement(createForm, 'email', 'email', '','');
createSpanTag(createForm,'emailError');
createElement(createForm, 'button','Validate','Validate','');
document.getElementsByTagName('button')[0].addEventListener('click',validate());
document.getElementsByTagName('body')[0].appendChild(newDiv);
}
)();
function createElement(formElement,type,name,value, placeholder) {
if(type=='label'){
var element=document.createElement(type);
if(name!='' && value!=''){
element.setAttribute('name',name);
element.setAttribute('value',value);
}
element.innerHTML=placeholder;
formElement.appendChild(element);
} else {
var element=document.createElement('input');
if(type!=''){
element.setAttribute('type',type);
}
if(name!=''){
element.setAttribute('name',name);
}
if(value!=''){
element.setAttribute('value',value);
}
if(placeholder!=''){
element.setAttribute('placeholder',placeholder);
}
formElement.appendChild(element);
}
}
function breakTag(createForm){
createForm.appendChild(document.createElement('br'));
}
function validate(){
}
function createSpanTag(createForm, id){
var element=document.createElement('span');
element.setAttribute('id',id);
createForm.appendChild(element);
}
The second argument of addEventListener needs to be a function.
Change ...
document.getElementsByTagName('button')[0].addEventListener('click',validate())
to ...
document.getElementsByTagName('button')[0].addEventListener('click',validate);
Since your tag name is input, not button. So use input in parameter of the function getElementsByTagName() and then loop through all nodes and find node with type = button.
Try change this line:
document.getElementsByTagName('button')[0].addEventListener('click',validate());
to:
var nodeList = document.getElementsByTagName("input");
for (var i = 0; i < nodeList.length; i++)
{
if (nodeList[i].getAttribute("type") == "button") {
{
nodeList[i].addEventListener('click',validate);
}
}
I have One simple registration Form which is developed in C#.Net. This form also contain one Grid view which display data from database.In this,I want to disable Insert button when i select particular raw data. and i had develop this code in jquery. I used below code.
function DoStuff(lnk) {
debugger;
var grid = document.getElementById('GridView1');
var cell, row, rowIndex, cellIndex;
cell = lnk.parentNode;
row = cell.parentNode;
rowIndex = row.rowIndex;
cellIndex = cell.cellIndex;
var rowId = grid.rows[rowIndex].cells[0].textContent;
var rowname = grid.rows[rowIndex].cells[1].textContent;
var rowcontact = grid.rows[rowIndex].cells[2].innerHTML;
var rowaddress = grid.rows[rowIndex].cells[3].innerHTML;
var rowemail = grid.rows[rowIndex].cells[4].innerHTML;
var Id = document.getElementById('txt_Id');
var name = document.getElementById('txt_Name');
var contact = document.getElementById('txt_PhoneNumber');
var address = document.getElementById('txt_Address');
var email = document.getElementById('txt_EmailId');
Id.value = rowId;
name.value = rowname;
contact.value = rowcontact;
address.value = rowaddress;
email.value = rowemail;
document.getElementById('Button1').disabled = true;
};
But when i run that page it becomes disable and immediately enable automatically.....:(
Can anyone give me solution ???
You have to call this function after form is completely loaded.
Use below code to make it that happen if you are using jQuery.
$( document ).ready(function() {
DoStuff(lnk);
});
Using jQuery I am making an ajax call to append data to some input fields, jquery is changing the DOM but the changes are not appearing in the inputs until I click on them.
Here is my jquery code:
var data_track = '';
var data_image = '';
var data_artist = '';
var data_album = '';
var data_duration = '';
var data_mbid = '';
if(data.track.name) {data_track = data.track.name;}else{ data_track = '';}
if(data.track.album) {data_image = data.track.album.image[3]['#text'];}else{ data_image = 'http://placehold.it/250x250';}
if(data.track.artist.name) {data_artist = data.track.artist.name;}else{ data_artist = '';}
if(data.track.album) {data_album = data.track.album.title;}else{ data_album = '';}
if(data.track.duration) {data_duration = data.track.duration;}else{ data_duration = '';}
if(data.track.mbid) {data_mbid = data.track.mbid;}else{ data_mbid = '';}
$('#track-name').val(data_track);
$('#image').val(data_image);
$('#image_preview').attr('src', data_image);
$('#artist').val(data_artist);
$('#album').val(data_album);
$('#duration').val(data_duration);
$('#mbid').val(data_mbid);
$('#results').html('');
It works for me: http://jsfiddle.net/b4revvz6/2/
Check your data object;
There was another problem this code was inside ajax call and when i scored it $('#results').html('');
out of ajax, code working perfectly