<%# Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs"
Inherits="APIToDatabase.WebForm1" %>
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml">
<<head>
<title></title>
<script type="text/javascript">
function connectDb()
{
var ConnDB = new ActiveXObject("ADODB.Connection");
ConnDB.ConnectionString="Driver={ODBC Driver 13 for SQL Server};Server=tcp:yueloongserver.database.windows.net,1433;Database=LocationDatabase;Uid=;Pwd=;Encrypt=yes;TrustServerCertificate=no;Connection Timeout=30;";
ConnDB.Open();
var Rs = new ActiveXObject("ADODB.Recordset");
var tempstr = "";
Rs.Open("select Latitude,Longitude from dbo.GPS",ConnDB);
while(!Rs.EOF === true)
{
tempstr = tempstr + Rs("Latitude") + "" + Rs("Longitude");
Rs.MoveNext;
}
test.innerHTML = tempstr;
}
</script>
</head>
<body>
<p><div id=test> </div>
<p><input id="button1" type="button" value="Run" name="button1" onclick="connectDb();"></p>
</body>
</script>
Hi, i am having the problem where i am able to only retrieve one column from the database. However, i would like to retrieve all the columns from the database table.
Related
def email_verification(email,password):
message = Mail(
from_email='hesheitaliabu#gmail.com',
to_emails=email,
subject='HEY BABYYYYYYYYYYYYYYYYYYY',
html_content=f"""
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<body>
<button onclick="myFunction()">Replace document</button>
<script>
function myFunction() {
window.location.href = "email_verify/" + email + "/" + password;
}
</script>
</body>
</html>
""")
Sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('MyAPI'))
Sg.send(message)
I have define a function called "email_verification" on FLASK to send the email with HTML design. I have used the f-string for the HTML content. But, I get a red curve line under the line of window.location.href = "email_verify/" + email + "/" + password;.
You need to escape literal braces {} in f-Strings in python.
You do this by doubling them. e.g.
def email_verification(email,password):
message = Mail(
from_email='hesheitaliabu#gmail.com',
to_emails=email,
subject='HEY BABYYYYYYYYYYYYYYYYYYY',
html_content=f"""
<!DOCTYPE html>
<html lang="en" xmlns="http://www.w3.org/1999/xhtml" xmlns:v="urn:schemas-microsoft-com:vml" xmlns:o="urn:schemas-microsoft-com:office:office">
<body>
<button onclick="myFunction()">Replace document</button>
<script>
function myFunction() {{
window.location.href = "email_verify/" + email + "/" + password;
}}
</script>
</body>
</html>
""")
Sg = sendgrid.SendGridAPIClient(api_key=os.environ.get('MyAPI'))
Sg.send(message)
Notice here in the syntax highlighting how the body of myFunction is part of the f-String (green) and not a template variable (white) as in your question.
See https://realpython.com/python-f-strings/#braces
I need to get a list of innerHTML strings from a website (for example facebook) to my .NET application.
Is there a way to get results from the following function into my application (i would put this data into a list) :
var data = new Array();
for(i=0; i<document.getElementsByClassName("class-name").length;i++)
data.push(document.getElementsByClassName("class-name")[i].innerHTML);
The code above outputs exactly the data i need, now my question is if it's possible to somehow get this data into my c# list?
This is how I'd like it to look :
var JS_DATA = data; //get the js array as a variable
static List<string> data = new List<string>(); //make a new list
foreach (string str in JS_DATA)
data.Add(String.Format("{0}", str)); //add the whole js array to the list
Here is an example:
see hidden Field array_store
Client side:
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title></title>
<script type="text/javascript">
var array_store;
window.onload = function () {
array_store = document.getElementById("array_store");
document.getElementById("array_disp").innerHTML = array_store.value;
};
function UpdateArray() {
var arr;
if (array_store.value == "") {
arr = new Array();
} else {
arr = array_store.value.split(",");
}
arr.push((arr.length + 1).toString());
array_store.value = arr.join(",");
};
</script>
</head>
<body>
<form id="form1" runat="server">
<span id="array_disp"></span>
<br />
<asp:Button ID="btnSubmit" runat="server" Text="Submit" OnClientClick="UpdateArray()" />
<input type="hidden" id="array_store" name = "ArrayStore" value = '<%=this.ArrayStore %>' />
</form>
</body>
</html>
C#:
protected string ArrayStore = "";
protected void Page_Load(object sender, EventArgs e)
{
this.ArrayStore = Request.Form["ArrayStore"];
}
I am learning JavaScript.
I've written this code, but it does not seem to run.
<!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>
<meta content="text/html; charset=utf-8" http-equiv="Content-Type" />
<script language="javascript" type="text/javascript">
function nav(){
try{
var str="<table border=1>";
for (var n in navigator){
str+="<tr><td>" + n + "</td></tr>";
}
str+="</table>
return("jetzt wird das Ding aufgelistet: <br/>" + str);
}catch(e){return(e);}
}
function writeit(){
document.write(nav());
}
</script>
<title>for learning purpos</title>
</head>
<body>
<form>
<script>
document.write(nav());
</script>
<p>press the button to get the properties in navigator</p>
<input type="button" id="btnNavigator" value="get" onclick="writeit();"/>
</form>
</body>
</html>
You haven't closed one string.
str+="</table>";
Best practice is to look into the console from developer tab, inspect page. Also on that tab on the bottom, you can try javascript code or even jQuery if you have the library added.
Your code it's wrong at line 13 you have Invalid or unexpected token because you didn't close the string and at line 30 nav it's not defined.
You can use this code:
function navBuild(n)
{
var tblS = "<table>";
var tblE = "</table>";
var strTrTd = "";
for (i=1; i<=n; i++)
{
strTrTd = strTrTd + "<tr><td>" + i + "</td></tr>";
}
var strAll = tblS + strTrTd + tblE;
console.log(strAll);
document.getElementById("contentBox").innerHTML = strAll;
}
And in your HTML you could use:
<input type="button" id="btnNavigator" value="get" onclick="navBuild(5);"/>
<div id="contentBox"></div>
I am try to automatically fire a sub routine with with a javascript "document.getElementById('button2').click();" as it is in the below code. Can someone please help me see why the code is not working. Thank you
<%# Page Language="VB" ContentType="text/html" ResponseEncoding="iso-8859-1" debug = "true"%>
<%# Import Namespace="System.Data.SqlClient"%>
<%# Import Namespace="System.Data"%>
<script language="vb" runat="server">
Sub sendmsg(sender As Object, e As EventArgs)
response.Redirect("index.aspx")
End Sub
</script>
<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
<script>
function Confirm() {
var str = $('#loutput').val(); //'We are inviting you for s special business meeting on Tueday, at No 12, Fred street. for more information please call 02341123333';
var updateString = function(input_text) {
//1. Find consecutive 11 numeric digits
var match = input_text.match(/\d{11}/);
//2. divide it into a string of 3s separated by space
var new_str = '';
for (var i = 1; i < match[0].length + 1; i++) {
new_str = new_str + match[0][i - 1];
if (i > 1 && i % 3 == 0)
new_str = new_str + ' ';
}
//3. Replace old match no. with the new one
console.log(match)
if (match[0] != '')
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm("Message contains numeric characters which might make the message not delivered to some networks. Do you want us to reformat the message ?. This might increase the numbers of pages of the message and the cost?")) {
confirm_value.value = "Yes";
input_text = input_text.replace(match[0], new_str)
$('#loutput').val(input_text);
confirm2()
//document.getElementById('loutput').innerHTML = input_text;
} else {
confirm_value.value = "No";
confirm2()
}
$('#loutput').val(input_text);
//document.getElementById('loutput').innerHTML = input_text;
};
updateString(str);
};
function confirm2() {
var confirm_value = document.createElement("INPUT");
confirm_value.type = "hidden";
confirm_value.name = "confirm_value";
if (confirm(" send the message now?")) {
confirm_value.value = "Yes";
document.getElementById('button2').click();
//document.getElementById('loutput').innerHTML = input_text;
} else {
confirm_value.value = "No";
}
//document.getElementById('loutput').innerHTML = input_text;
};
</script>
</head>
<body>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"> </script>
<form runat="server" action="formatmessage3.aspx" method="post">
<input type="texarea" id="loutput" name="loutput" value="<%=request.form ("loutput") %>" />
<button ID="button1" OnClick="Confirm();" runat="server">Confirm</button>
<asp:button ID="button2" OnClick="sendmsg" Text="send" runat="server" />
</form>
</body>
</html>
The problem here is the fact you are using a .NET button with runat="server" so it is going to change the id of the button to a different value.
<asp:button ID="button2" OnClick="sendmsg" Text="send" runat="server" />
You either have to reference the element by a class
document.getElementsByClassName("myClass")[0].click();
or reference the dynamic name
document.getElementById("<%= button2.ClientID %>").click();
or in .NET4 you can use ClientIDMode="Static"
I have function that opens up a window, and the values from the newly opened window are listed in the opener window.
The 2nd window - has this function:
function AddOtherRefDoc(name, number) {
var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>";
var html = "<li><b> Referral Doctor: </b>"+name+"<b>, Referral No: </b>"+number+ " " +remove+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text' name='ref_nos' value='"+number+"'></input></li>";
opener.jQuery("#r_docs").append(jQuery(html));
}
The function that calls the one above is:
function addRefDoc(){
var count = 0;
var ref_docarray ;
var ref_noarray ;
<%for(int i1=0; i1<vec.size(); i1++) {
prop = (Properties) vec.get(i1);
String ref_no = prop.getProperty("referral_no","");
String ref_name = (prop.getProperty("last_name", "")+ ","+ prop.getProperty("first_name", ""));
%>
if(document.getElementById("refcheckbox_<%=ref_no%>").checked) {
count++;
if ((ref_doctor!=null)&&(ref_doctor!="")&&(ref_docno!=null)&&(ref_docno!="")) {
ref_docarray = ref_doctor.split(";");
ref_noarray = ref_docno.split(";");
if ((containsElem(ref_docarray,"<%=ref_name%>"))||(containsElem(ref_noarray,<%=ref_no%>))) {
alert("Referral doctor " + "<%=ref_name%>" + " already exists");
} else {
AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
}
} else {
AddOtherRefDoc("<%=ref_name%>", <%=ref_no%>);
}
}
<%} %>
self.close();
}
function containsElem(array1,elem) {
for (var i=0;i<array1.length;i++) {
if(array1[i]==elem){
return true;
} else{
return false;
}
}
}
When this function is called, it is supposed to carry the 2 input elements "ref_docs" and "ref_nos" into the page that opened this window. But it is not doing so. It lists the elements alright but when I try to use "ref_docs" and "ref_nos" in another Javascript function in the 1st window, I see that "ref_nos" and "ref_docs" are empty.
What am I doing wrong?
function updateRd(){
var ref_docs = jQuery("#updatedelete").find('input[name="ref_docs"]');
var ref_nos = jQuery("#updatedelete").find('input[name="ref_nos"]'); alert(ref_docs.val() + ref_nos.val());
var rdocs = new Array();
var rnos = new Array();
ref_docs.each(function() { rdocs.push($(this).val()); } );
ref_nos.each(function() { rnos.push($(this).val()); } );
$('#r_doctor').val(rdocs.join(";"));
$('#r_doctor_ohip').val(rnos.join(";")); }
–
This function returns an error saying "ref_docs" and "ref_nos" are undefined.
I think it is trying to use the jQuery on the other page to find "#r_docs" on the current page.
Try:
jQuery(opener.document).find("#r_docs").append(html);
UPDATE:
I created index.html:
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript">
window.jQuery = jQuery;
function openChild ()
{
var mychildwin = window.open("child.html");
}
</script>
</head>
<body>
<input type="button" value="click" onclick="openChild();" />
<div id="r_docs">
Redocs here.
</div>
</body>
</html>
and child.html:
<!DOCTYPE html>
<html><head>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<title> - jsFiddle demo</title>
<script type="text/javascript" src="http://code.jquery.com/jquery-1.5.2.js"></script>
<script type="text/javascript">
function AddOtherRefDoc(name, number) {
var remove = "<a href='javascript:void(0);' onclick='removeRefDoctor(this)'>Remove</a>";
var html = "<li><b> Referral Doctor: </b>"+name+"<b>, Referral No: </b>"+number+ " " +remove+" <input type='text' name='ref_docs' value='"+name+"'></input><input type='text' name='ref_nos' value='"+number+"'></input></li>";
jQuery(opener.document).find("#r_docs").append(html);
}
</script>
</head>
<body>
<input type="button" value="click" onclick="AddOtherRefDoc('name', 42);"/>
</body>
</html>
UPDATE2:
in your update function document.updatedelete has no attributes ref_docs and ref_nos.
try:
jQuery("#updatedelete")
.find('input[name="ref_docs"], input[name="ref_nos"]')
Where your form is
<form id="updatedelete" ... >
Your function that accesses the DOM elements is incorrect. updatedelete is not a property of document, nor will accessing a ref_docs or ref_nos property automatically build a collection of input elements. Since you're using jQuery already, try this:
var ref_docs = $('input[name="ref_docs"]');
var ref_nos = $('input[name="ref_nos"]');
That will give you Array (or at least array-like) objects that will let you access your inputs:
var rdocs = new Array();
var rnos = new Array();
ref_docs.each(function() { rdocs.push($(this).val()); } );
ref_nos.each(function() { rnos.push($(this).val()); } );
$('#r_doctor').val(rdocs.join(";"));
$('#r_doctor_ohip').val(rnos.join(";"));