getElementByID doesn't working with xmlDoc - javascript

I am trying to learn xml and ajax for a school project I am currently working on. I need to create a chat system between two users and because I am still learning I do some "experiments" to see how things work.
I am trying to get information from an xml file and to print the information on but the problem is after I get the xmlDoc. , and press CTRL+SPACE, I don't see that I have any getElement option.
This is the XMLFile:
<?xml version="1.0" encoding="utf-8" ?>
<Conversation>
<Massage>
<To>a</To>
<From>b</From>
<Text>a to b</Text>
<Date>11/12/2014</Date>
</Massage>
<Massage>
<To>b</To>
<From>a</From>
<Text>b to a</Text>
<Date>11/12/2014</Date>
</Massage>
</Conversation>
And this is the html file:
<%# Page Language="C#" AutoEventWireup="true" CodeFile="Default.aspx.cs" Inherits="_Default" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
function LoadXMLDoc(FileName) {
var xmlhttp;
if (window.XMLHttpRequest())
xmlhttp = new XMLHttpRequest();
else
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
xmlhttp.open("GET", FileName, false);
xmlhttp.send();
return xmlhttp.response;
}
</script>
</head>
<body>
<script>
function Function() {
var xmlDoc = LoadXMLDoc("XMLFile.xml");
}
</script>
<form id="form1" runat="server">
<div>
<center>
<h1> Chat </h1>
<div id="Box" style="position:relative;height:200px;width:400px;border-width:2px;border-style:solid;border-color:black">
<div id="Conversation">
</div>
<div id="Write" style="position:absolute; bottom:0;right:0;">
<input type="text" id="MassageText" />
<button id="SendMassageButton" causesvalidation="False" type="submit" onclick="Function(); return false">Send</button>
</div>
</div>
</center>
</div>
</form>
</body>
</html>
I am learning with w3school and I don't see any problems here.
Maybe there is a problem with the intellisense? I had an error message about that when I was trying to create a for loop.
B.T.W sorry if I have a bad english.

Related

How to call js extern function from asp net page

I have this page in cshtml.
This page execute submit in "formImpressao" (ASP.NET PAGE)
CSHTML page
#using Web.Mvc.Helpers
#{
string msgSucesso = "test";
}
<div id="divSucess">
<h5 style="background-image: url('themes/base/images/48/ico_ok.gif'); text-align:center; background-repeat: no-repeat; font-family: Verdana; color: #1d7100; font-size:'72'">#msgSucesso</h5>
</div>
<div id="HiddenFormTarget" style="display:none;">
<form id="formImpressao" method="post" target="frmPrint" action="/VisualizarRelatorios/ImprimirRelatorio.aspx"></form>
</div>
<iframe id="frmPrint" name="frmPrint" width="0" height="0" runat="server">
</iframe>
<script language="javascript" type="text/javascript">
$("#formImpressao").submit();
</script>
ASPX Page (ImprimirRelatorio.aspx)
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="ImprimirRelatorio.aspx.cs" Inherits="Views.Views.ImprimirRelatorios.ImprimirRelatorio" %>
<%# Register Assembly="Microsoft.ReportViewer.WebForms, Version=10.0.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a"
Namespace="Microsoft.Reporting.WebForms" TagPrefix="rsweb" %>
<%--<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">--%>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="../Scripts/jquery-1.5.1.js" type="text/javascript"></script>
<script src="../Scripts/jquery-1.5.1.min.js" type="text/javascript"></script>
</head>
<body style="margin: 0px">
<form id="form1" runat="server" style=" width:100%; height:100%;" >
<div style=" width:100%; height:100%; overflow-y:hidden; overflow-x:hidden" >
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<rsweb:ReportViewer ID="rptRelatorio" runat="server" Width="100%"
Height="100%" ProcessingMode="Remote" >
</rsweb:ReportViewer>
</div>
</form>
</body>
</html>
<script language="javascript">
function Imprimir()
{
var viewer = $find("rptRelatorio");
var isLoading = viewer.get_isLoading();
var impresso = false;
if (!isLoading) {
$("input[type='image']:not(:disabled)[title*='Print']").click();
impresso = true;
}
if (!impresso) {
setTimeout(Imprimir, 1000);
}else {
$("#divSucess").style.backgroundColor = "red";
}
}
$(document).ready(function () {
setTimeout(Imprimir, 4000);
});
</script>
The Imprimir function on validates whether the report was printed within Reporting Services.
If printed, it needs to assign to div divSuccess, the attribute: style.backgroundColor = "red".
The problem is that the asp form does not see the divSuccess and the cshtml page does not display the asp form.
How can I call a js function inside the asp page to play the DOM of the page that has the "divSuccess"?
Are there other ways to do this?
The two pages do not talk.
You could send AJAX request to get content of ImprimirRelatorio.aspx page. In success handler you could parse response to get inner HTML of body tag of the ImprimirRelatorio.aspx page, set result to some container (without <iframe>) and call Imprimir function (see details in AJAX documentation). Note, the Imprimir function should be a part of success event handler of should be defined in the calling page.

How to print webpage without print preview on ButtonClick using Javascript in asp.net

I wrote this code but still print preview option is coming...
this.contentWindow.print() for printing purpose
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script>
function printPage()
{
var div = document.getElementById("printerDiv");
div.innerHTML = '<iframe src="PrintDemo.aspx" onload="this.contentWindow.print();"></iframe>';
}
</script>
</head>
<body>
<form id="form1" runat="server">
<div>
<button onclick="printPage()">prin`enter code here`t</button>
<div id="printerDiv" ">
This Page Is for print demo`enter code here`
</div>
</div>
</form>
</body>
</html>

Javascript error if not in Form section

I have this javascript:
<head runat="server">
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
<script type="text/javascript">
function ageProb() {
var DatePicker1 = $find("<%= RadDatePicker1.ClientID %>");
DatePicker1.get_dateInput()._textBoxElement.style.backgroundColor = "yellow";
DatePicker1.get_dateInput().focus();
}
</script>
When I run the code I get this error:"Impossible to modify the Controls collection because the control contains code blocks (like <% ... %>)"
If I move the Javascript into the Form section (I found this advice googling around) then the error does not occurs but I am under the impression that the function does not get the call:
ScriptManager.RegisterStartupScript(this, GetType(), "ageProb", "ageProb();", true);
I do I fix this problem?
Do this and it will work, but you should put it in the body:
<body>
<form id="form1" runat="server">
<asp:Panel runat="server">
<script type="text/javascript">
function ageProb() {
var DatePicker1 = $find("<%= RadDatePicker1.ClientID %>");
DatePicker1.get_dateInput()._textBoxElement.style.backgroundColor = "yellow";
DatePicker1.get_dateInput().focus();
}
</script>
</asp:Panel>
</form>
</body>

Values wont reflect

This is a very beginner level question as I just started to look at knockout js by downloading js,referring it in my web app.
My simple aspx code. based on first tutorial on knockout js site learning page.
<%# Page Language="C#" AutoEventWireup="true" CodeBehind="KnockoutDemo.aspx.cs" Inherits="knockoutjs.KnockoutDemo" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script src="javascripts/knockout-3.2.0.js" type="text/javascript"></script>
</head>
<body>
<form id="form1" runat="server">
<script type="text/javascript">
function AppViewModel() {
debugger;
this.firstName = "XYZ";
this.lastName = "UU";
}
function callKnockOut() {
debugger;
ko.applyBindings(new AppViewModel());
}
</script>
<div>
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<button id="click" onclick="callKnockOut();"></button>
</div>
</form>
</body>
</html>
ideally the values should take effect after I click button.the code runs through successfully.labels won't show anything!
Knockout is client side javascript library, and you are submitting your form to server so instead of that don't run this at server run it to client i.e. dont write runat="server" for form tag. Then this will absolutely work.
function AppViewModel() {
debugger;
this.firstName = "XYZ";
this.lastName = "UU";
}
function callKnockOut() {
debugger;
ko.applyBindings(new AppViewModel());
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/knockout/3.2.0/knockout-min.js"></script>
<form id="form1" action="#">
<div>
<p>First name: <strong data-bind="text: firstName"></strong></p>
<p>Last name: <strong data-bind="text: lastName"></strong></p>
<button id="click" onclick="callKnockOut();">submit</button>
</div>
</form>

how to close a browser having pdf inside it

i have an browser with pdf which is opened on clicking "viewPDF" button in the main page of an asp.net and c#.net application.
On clicking the "viewPdf" button i am opening the pdf in the browser using the javascript as below:
<script language="javascript">
function openpdf()
{
var pdfobj= window.open('epcrpdf.aspx');
}
</script>
in the design page.
<input id="btnTakeAction"
class="Button"
type="button" value="View Pdf"
onclick="javscript:openpdf();">
The problem is i also have a log out button in the mainpage, on cliking the log out button i have to close the childwindows like the browser containing pdf.
when i try to close the browser containing using javscript as below i face a problem of "Access is denied".
pdfobj.close();
but other browsers which does not contain pdf gets closed with out any error message.
This has worked for me:
<%# Page Title="Home Page" Language="C#" AutoEventWireup="true" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">
<head id="Head1" runat="server">
<title></title>
<script type="text/javascript">
var wnd = null;
function openPdf() {
wnd = window.open('test.pdf');
}
function closePdf() {
if (wnd != null) {
wnd.close();
}
}
</script>
</head>
<body>
<form id="Form1" runat="server">
<input type="button" name="open" value="Open" onclick="openPdf();" />
<input type="button" name="close" value="Close" onclick="closePdf();" />
</form>
</body>
</html>

Categories

Resources