|
Hi,
I need a Modal Dialog for a customer to submit their account code and password. I have put the following Java Script together:-
<SCRIPT LANGUAGE="JavaScript" TYPE="text/javascript">
<!--
function LoginToAccount() {
window.open("LogIn/LoginForm.html", "","width=350,height=150")
}
</SCRIPT>
It works of sorts, the form appears on the screen, but:-
- it appears at the Top Left Corner rather than Centre Screen
- It contains the Source Bar, and all the windows furniture.
- The Dialog is not Modal.
Is there a way to remedie this, or am I totally on the wrong path.
Kind Regards,
Bram van Kampen
|
|
|
|
|
|
Hi,
I have a Web Api as below:
[Route("api/PeakTimeRebate")]
public class PeakTimeRebateController : Controller
{
[HttpGet("GetTransactionStatus")]
[DecryptoFilter]
public IActionResult GetTransactionStatus(string EncryptedAccountNumber)
{
this.Response.ContentType = "text/html";
int randVal = new Random().Next(0, 10);
if ((randVal == 1) || (randVal == 2) || (randVal == 3) || (randVal == 5) || (randVal == 7))
return new ObjectResult("Prime");
if (randVal % 2 == 0)
{
return new ObjectResult("Even");
}
else
{
return new ObjectResult("Odd");
}
}
}
I am calling this from a Angular Service as below:
@Injectable()
export class PeakTimeRebatesService extends ServiceBase {
private _peaktimerebateTransactionStatusUrl: string = '/api/PeakTimeRebate/GetTransactionStatus';
constructor(public _http: PgeCustomHttp) {
super(_http);
}
public peakTimeRebateTransactionStatus(encryptedAccountNumber: string): Observable<string> {
debugger;
const params: URLSearchParams = new URLSearchParams();
params.set('EncryptedAccountNumber', encryptedAccountNumber);
const options = new RequestOptions({ search: params });
return this._http.get(this._peaktimerebateTransactionStatusUrl, options)
.map(this.extractBoolean)
.catch(this.handleError);
};
};
I already have imported necessary components for the Service that I haven't mentioned here.
Now I have a component as below:
import { PeakTimeRebatesService } from '../peakTimeRebates/peakTimeRebates.service';
@Component({
selector: 'transactionSuccessful-message',
templateUrl: 'transactionSuccessful.component.html'
})
export class TransactionSuccessfulComponent extends ComponentBase {
@Input()
public TransactionMessage: string = '';
public TransactionSuccessStatus = false;
public TransactionExceptionStatus = false;
private max: number = 10; private min: number = 0; private randVal: number; private checkStatMessage: string;
@Input()
public get EncryptedAccountNumber() {
debugger;
return this._encryptedAccountNumber;
}
public set EncryptedAccountNumber(value: string) {
debugger;
if ((value == null) || (value == '')) {
value = 'XYZ'
}
this._encryptedAccountNumber = value;
if (this.EncryptedAccountNumber !== '') {
this.peakTimeRebateTransactionStatus(this.EncryptedAccountNumber);
}
}
private _encryptedAccountNumber: string = '';
public constructor(
private _service: PeakTimeRebatesService
) {
super();
debugger;
}
private peakTimeRebateTransactionStatus(encryptedAccountNumber: string): void {
debugger;
this._service.peakTimeRebateTransactionStatus(encryptedAccountNumber).subscribe((peakTimeRebateTransactionStatus: any) => {
this.TransactionMessage = peakTimeRebateTransactionStatus;
});
}
ngOnInit(): void {
debugger;
this.EncryptedAccountNumber = '';
if (this.TransactionMessage == "Prime")
{
this.TransactionSuccessStatus = true;
}
else if (this.TransactionMessage == "Even")
{
this.TransactionSuccessStatus = false;
}
else
{
this.TransactionExceptionStatus = true;
}
}
}
And finally my html component is:
<div class="layout-two-column">
<section class="layout-primary">
<form #payBillSuccessForm="ngForm" id="payBillSuccessForm" name="payBillSuccessForm" novalidate>
<div *ngIf="TransactionSuccessStatus">
<h2 id="transactionSucessfulText">{{ 'Common.EnrollmentSuccessful' | Translate }}</h2>
</div>
<div *ngIf="!TransactionSuccessStatus">
<h2 id="transactionFailedText">{{ 'PeakTimeRebatesView.EnrollmentSuccessMessage' | Translate }}</h2>
</div>
<div *ngIf="TransactionExceptionStatus">
<h2 id="transactionExceptionText">{{ 'PeakTimeRebatesView.PeakTimeRebatesHeader' | Translate }}</h2>
</div>
<div class="divider-invisible text-right">
<a class="btn" routerLink="/AccountInformation" id="doneButton">{{ 'Common.Done' | Translate }}</a>
</div>
</form>
</section>
</div>
<browser-back [lastpage]="true"></browser-back>
Now I am expecting that I want to show the message depending upon the returned value from web api, (the problem is that, the execution of the ngOnInit is finishing before execution of Web Api, I mean the setting of TransactionMessage is happening before the Web Api returns value, I am not sure why is it happening, I am new to the client side programming World) I found it when I put the break point, from onInit method before Service call is being completed the control is coming back and finishing the onInit then finishing the web api call, trying to understand how to call the web api from the angular controller, is the onInit not a right place to call the web api from the Angular Component. Any suggestions where am I making mistake? Any help would be very very helpful, thanks in advance. I am new to Angular, really need some help - please, thank you.
modified 29-Jan-19 16:17pm.
|
|
|
|
|
Hi all,
Can you help with this query..
How can we execute a next condition if the first condition is false. In the for loop statement in javascript.
|
|
|
|
|
The same way you would do it in code that is outside of a for loop: with an IF statement. Your question is not clear, perhaps if you show the code where the problem is, people will be able to make suggestions.
|
|
|
|
|
Easy.
for (int i = 0; i < 10; i++){
if (something == 1)
{
}
else{
}
}
Everyone is born right handed. Only the strongest overcome it.
Fight for left-handed rights and hand equality.
|
|
|
|
|
You should actually write if else ladder to check for another condition if one fails, like below;
for(var i = 0; i < 10; i++)
{
if(condition1==true)
{
}
else if(condition2==true)
{
}
else if(conditionN==true)
{
}
else
{
}
}
|
|
|
|
|
An alternative view of some of the previous answers.
Check for your condition.
Do what needs to be done.
Execute a continue or break
If our condition is false, it will simply continue down through instruction in the remainder of your loop.
Although methods like this or the others have specific circumstances. when they are preferred, more often than night it's simply a matter tastes.
An if/else ladder presumes any number of additional conditions may be added
If circumstances allow (depends on what you're testing for and the language), you can use a switch statement.
There are usually many solutions to each programming problem - often pretty much equal in quality. You'll eventually develop a style of your own that works best with your train of thought. And, of course, experience.
Ravings en masse^ |
---|
"The difference between genius and stupidity is that genius has its limits." - Albert Einstein | "If you are searching for perfection in others, then you seek disappointment. If you are seek perfection in yourself, then you will find failure." - Balboos HaGadol Mar 2010 |
|
|
|
|
|
Hi,
How do I debug JavaScript Code. I.E. Set Breakpoints and inspect values, etc.
Regards,
Bram van Kampen
|
|
|
|
|
|
Thanks Richard,
Never knew this. At least I do not have to buy expensive new tools. I am now 65, and have no formal training in Computer Science. The subject simply did not exist when I went to uni in 1972.
I am trying to teach myself java-script in the eye of necessity. I am coming to conclude that it's similarity to 'C' is only on the surface. It seems to work in dark and mysterious ways.
Good to hear from you again,
Bram van Kampen
|
|
|
|
|
I have picked up a fairly simple code from the internet but I am not understanding how it is making the connection with itself.
<style>
body {font-family: Arial;}
.tab {
overflow: hidden;
border: 1px solid #ccc;
background-color: #f1f1f1;
}
.tab button {
background-color: inherit;
float: left;
border: none;
outline: none;
cursor: pointer;
padding: 14px 16px;
transition: 0.3s;
font-size: 17px;
}
.tab button:hover {
background-color: #ddd;
}
.tab button.active {
background-color: #ccc;
}
.tabcontent {
display: none;
padding: 6px 12px;
border: 1px solid #ccc;
border-top: none;
}
</style>
<h2>Tabs</h2>
<p>Click on the buttons inside the tabbed menu:</p>
<div class="tab">
<button class="tablinks" onclick="openCity(event, 'London')">London</button>
<button class="tablinks" onclick="openCity(event, 'Paris')">Paris</button>
<button class="tablinks" onclick="openCity(event, 'Tokyo')">Tokyo</button>
</div>
<div id="London" class="tabcontent">
<h3>London</h3>
<p>London is the capital city of England.</p>
</div>
<div id="Paris" class="tabcontent">
<h3>Paris</h3>
<p>Paris is the capital of France.</p>
</div>
<div id="Tokyo" class="tabcontent">
<h3>Tokyo</h3>
<p>Tokyo is the capital of Japan.</p>
</div>
function openCity(evt, cityName) {
var i, tabcontent, tablinks;
tabcontent = document.getElementsByClassName("tabcontent");
for (i = 0; i < tabcontent.length; i++) {
tabcontent[i].style.display = "none";
}
tablinks = document.getElementsByClassName("tablinks");
for (i = 0; i < tablinks.length; i++) {
tablinks[i].className = tablinks[i].className.replace(" active", "");
}
document.getElementById(cityName).style.display = "block";
evt.currentTarget.className += " active";
}
For one thing, I don't understand why the button are put at class "tablinks" when such a class does not exist in the entire css. I kind of understand the Javascript and I am someone who is not familiar with Javascript that much. But I just don't understand how the CSS is being worked here.
I would also like to know how this code would work if I used a <href> links here instead of buttons. How would that make my code different?
Thanking in advance.
|
|
|
|
|
Member 14118143 wrote: I don't understand why the button are put at class "tablinks" when such a class does not exist in the entire css.
Because that class is being used to target the elements from the Javascript:
tablinks = document.getElementsByClassName("tablinks");
Document.getElementsByClassName() | MDN[^]
Member 14118143 wrote: I would also like to know how this code would work if I used a <href> links here instead of buttons. How would that make my code different?
The only difference would be that you would need to call evt.preventDefault() in your openCity method to prevent the browser from navigating to the href .
Event.preventDefault() | MDN[^]
"These people looked deep within my soul and assigned me a number based on the order in which I joined."
- Homer
|
|
|
|
|
This is not a JavaScript question, but more a Python question, and since I could not find a section here to post Python questions, I am posting it in the JavaScript section. Admins - please move this question to the appropriate forum, if you feel so.
From what little I know of TypeScript, it is a superset of JavaScript which is strongly typed. So, a TypeScript program should have function arguments declared, and return types declared. Also, a TypeScript program is transpiled to JavaScript, which is then run on the browser. This is my current understanding - please correct me if this is incorrect.
Now, I am in the process of converting a Python program to C++. A Python program can just define a function and its arguments without specifying their types, and it will only bomb at run time if the input data types do not match. Is there a version/superset of Python where strict argument type checking is done, and an intermediate compilation/transpilation step is used to check data types, and errors reported, which then generate the resulting Python program. ... (A)
The difficulty I am facing in converting the Python program to C++ is: I really don't know what are the argument types, and is the return type. These are needed to be coded in the C++ program. Any pointers in this regard are welcome. ... (B)
I am writing about two different things A and B above, and A is not likely a resolution of B. However, if someone can think on the lines of A above, and work towards a solution, I feel that it would help future persons working on converting Python code to C++.
|
|
|
|
|
A. As far as I ama aware Python does not offer strict type checking on variables. That is one of its strengths (allegedly).
B. The only way to know what type to declare is by studying the Python code and figuring it out from the context.
Note: there is not a specific Python forum here, but you can always use https://www.codeproject.com/Questions/ask.aspx[^].
|
|
|
|
|
Hi everyone.
I'm not sure if this question has been asked before or not.
I am trying to load/reference an external web site to my local project in a div.
For some reason, my boss doesn't want to use an Iframe to do this but inject that website to a div.
I had an issue with the CORS but added headers to get it and it worked but the problem is it doesn't get the scripts and styling sheets.
I have tried using the jquery Load as well but got the same results. Thanks.
Here is my code:
<div id="injection"></div>
<script>
$(document).ready(function () {
PageInjector('targetURL');
});
function PageInjector(url) {
$("#injection").html('');
$.ajax({
url: url,
method: "get",
success: function (data) {
$("#injection").html(data);
}
});
}
</script>
|
|
|
|
|
Unless you control the content of the external website, you can't really expect it to work. The external site's scripts and CSS will be relative to its own document root, which (if you're lucky) will end up as a child node inside your site's DOM.
|
|
|
|
|
I do have full access to the external site, its even hosted from our side.
That's why I was able to add the headers to the web.config file.
I just need to reference the very same site to a different page in a different project.
Thanks.
Melboure
|
|
|
|
|
Hi, I am trying to get a page to work properly offline. It uses EmberJS for rendering, RequireJS for defining modules. Since I have the page fully loaded I don't need any of the app-specific functionality. I just need user interaction on page to work. Here is example of HTML that I am trying to get to behave properly:
<div id="area49253971_6938" class="component interaction-component float-none clear-none interaction_booted">
<div role="status" class="int-prep hidden"></div>
<div>
<div class="data-field interaction-type">RevealContent</div>
<div class="interaction_title"></div>
<div class="interaction_content RevealContent" style="min-height: 400px; width: 400px;">
<div class="pointer">
<td>
<div id="area49253971_6940" class="component image-component float-left clear-none booted"><img src="somelink" height="50" width="30" title="" alt="" style="padding-right: 10px;"></div>
<p class="body" id="area49253971_6941">^__em>^__strong><a href="#">Some question</a></p>
</td>
</div>
<div style="display: block;">
<td>
<p class="body" id="area49253971_6942">^__strong>Some answer</p>
</td>
</div>
</div>
<div class="interaction_data" style="display: none;">
<div id="area49253971_6939" class="component table-component float-none clear-none ">
<div class="component_caption"></div>
</div>
</div>
</div>
</div>
It is just a simple hide/show interaction. Here is the code that the app uses to make this work:
define("site/mixins/interactions/reveal_content", ["exports", "jquery"], function (exports, _jquery) {
function RevealContent($el) {
this.el = $el;
this.interactionData = $el.find(".interaction_data");
this.container = $el.find(".interaction_content");
}
RevealContent.prototype = {
init: function init() {
var contentToReveal = (0, _jquery["default"])('<div />').append((0, _jquery["default"])(this.interactionData.find('td')[1]).detach());
var initialContent = (0, _jquery["default"])('<div class="pointer" />').append((0, _jquery["default"])(this.interactionData.find('td')[0]).detach());
this.container = this.container.parent().find('.RevealContent');
this.container.append(initialContent);
this.container.append(contentToReveal.hide());
initialContent.click(function () {
(0, _jquery["default"])(contentToReveal).slideToggle('slow');
});
initialContent.find('a').click(function (e) {
e.preventDefault();
});
}
};
exports["default"] = RevealContent;
});
I think this code depends on various app-specific touch points. So I am trying to get it to work using jQuery alone (though I would like to get it working as is...).
So I tried this:
$(document).ready(function() {
$(this).on('click', '.interaction_booted', function () {
interactionData = $(this).find(".interaction_data");
this.container = $(this).find(".interaction_content");
var contentToReveal = $('<div />').append($(interactionData.find('tdd')[1]).detach());
var initialContent = $('<div class="pointer" />').append($(interactionData.find('tdd')[0]).detach());
this.container = this.container.parent().find('.RevealContent');
this.container.append(initialContent);
this.container.append(contentToReveal.hide());
initialContent.click(function () {
$(contentToReveal).slideToggle('slow');
});
});
});
Notice I changed the td elements to tdd because these td elements are without a table parent and Chrome was removing the td tags that this script looks for. So in my tests I changed the HTML tags as well. So in the above HTML, I am actually using <tdd>.
Now I have interactionData and this.container returning same values as the remote version of the site, as confirmed by stepping through the js code in Chrome. But things fail at these lines
var contentToReveal = $('<div />').append($(interactionData.find('tdd')[1]).detach());
var initialContent = $('<div class="pointer" />').append($(interactionData.find('tdd')[0]).detach());
What I mean by fail, is the return vales are not the same as on the remote page. The tdd elements are not being returned. Now I have no idea what these two lines of code even mean. And not sure what an append() function followed by detach() is supposed to be doing...
In the original code above these lines are
var contentToReveal = (0, _jquery["default"])('<div />').append((0, _jquery["default"])(this.interactionData.find('td')[1]).detach());
var initialContent = (0, _jquery["default"])('<div class="pointer" />').append((0, _jquery["default"])(this.interactionData.find('td')[0]).detach());
I took a guess that (0, _jquery["default"]) is the jQuery operator $.
But really, I have no idea what I have to do to get this to work as plain jQuery. So that is why I am here.
Can anyone help me get this working?
Thanks!
|
|
|
|
|
Hi,
What are the (Human Understandable) Rules for Scope and Type declarations, etc. for Java Script. I come from a C/CPP/MFC background, where all these things are clearly defined. Is it like early Basic, with a global scope? or what. a reference to a site, or a small book would be much appreciated.
Kind Regards,
Bram van Kampen
|
|
|
|
|
As far as I recall, Javascript is loosely typed. I am not sure the specifics of scope, but take a look at JavaScript | MDN[^].
|
|
|
|
|
Scope depends on what declaration you use. The old "var" declaration gives you function scope, where everything in a given function and sub function can refer to that scope (because "this" can mess that up big time, and is likely one of the hardest things to get used to in JS). ES 2016+ introduces the "let" declaration, which has proper block scope.
Global scope comes from either declaring a var outside of a function block, or the cleaner approach of attaching it to the window object:
var variable = value;
window.variable = value;
In classically-driven approaches to JS, the window object is effectively the global namespace.
"Never attribute to malice that which can be explained by stupidity."
- Hanlon's Razor
|
|
|
|
|
I have 3 nav bars on my angular page and need to stick 3rd nav bar when window is scroll. It behave weird on different browsers.
Is there any way to pick the top position of 3rd nav bar when window is scrolled and reached top of browser window? I tried with offsetTop and scrollTop but these values are fixed always.
modified 20-Sep-20 21:01pm.
|
|
|
|
|
|
I have a put method in web api as below:
[HttpPut("{id}")]
public int Edit(int id, TblEmployee employee)
{
return objemployee.UpdateEmployee(employee);
}
My Web Api methods are as follows, for some reason I am not able to call these Web Api methods, am I doing anything wrong these methods, please let me know:
[Produces("application/json")]
[Route("api/Employee")]
public class EmployeeController : Controller
{
EmployeeDataAccessLayer objemployee = new EmployeeDataAccessLayer();
[HttpGet("[action]")]
public IEnumerable<TblEmployee> Index()
{
return objemployee.GetAllEmployees();
}
[HttpPost]
public int Create(TblEmployee employee)
{
return objemployee.AddEmployee(employee);
}
[HttpGet("{id}")]
public TblEmployee Details(int id)
{
return objemployee.GetEmployeeData(id);
}
[HttpPut("{id}")]
public int Edit(int id, TblEmployee employee)
{
return objemployee.UpdateEmployee(employee);
}
[HttpDelete("{id}")]
public int Delete(int id)
{
return objemployee.DeleteEmployee(id);
}
[HttpGet("[action]")]
public IEnumerable<TblCities> GetCityList()
{
return objemployee.GetCities();
}
}
I am trying to call this method using reactjs component, I am not able to call this method, can you please help me where am I making mistake
Here is my Table rendering component:
private renderEmployeeTable(empList: EmployeeData[]) {
return <table className='table'>
<thead>
<tr>
<th></th>
<th>EmployeeId</th>
<th>Name</th>
<th>Gender</th>
<th>Department</th>
<th>City</th>
</tr>
</thead>
<tbody>
{empList.map(emp =>
<tr key={emp.employeeId}>
<td></td>
<td>{emp.employeeId}</td>
<td>{emp.name}</td>
<td>{emp.gender}</td>
<td>{emp.department}</td>
<td>{emp.city}</td>
<td>
<a className="action" onClick={(id) => this.handleEdit(emp.employeeId)}>Edit</a> |
<a className="action" onClick={(id) => this.handleDelete(emp.employeeId)}>Delete</a>
</td>
</tr>
)}
</tbody>
</table>;
}
Now I am calling it as below the Edit method as below
private handleEdit(id: number) {
this.props.history.push("api/employee/edit/" + id);
}
And I have Delete Web Api method that's not being called too from the above ts script file
[HttpDelete("{id}")]
public int Delete(int id)
{
return objemployee.DeleteEmployee(id);
}
And I have Create method which is supposed to be called by ts file at the time of save button click that's not being called as well:
[HttpPost]
public int Create(TblEmployee employee)
{
return objemployee.AddEmployee(employee);
}
The ts script for the create call is as below on the save button click:
import * as React from 'react';
import { RouteComponentProps } from 'react-router';
import { Link, NavLink } from 'react-router-dom';
import { EmployeeData } from './FetchEmployee';
interface AddEmployeeDataState {
title: string;
loading: boolean;
cityList: Array<any>;
empData: EmployeeData;
}
export class AddEmployee extends React.Component<RouteComponentProps<{}>, AddEmployeeDataState> {
constructor(props) {
super(props);
this.state = { title: "", loading: true, cityList: [], empData: new EmployeeData };
fetch('api/Employee/GetCityList')
.then(response => response.json() as Promise<Array<any>>)
.then(data => {
this.setState({ cityList: data }
);
console.log(data);
});
var empid = this.props.match.params["empid"];
if (empid > 0) {
fetch('api/Employee/Details/' + empid)
.then(response => response.json() as Promise<EmployeeData>)
.then(data => {
this.setState({ title: "Edit", loading: false, empData: data });
});
}
else {
this.state = { title: "Create", loading: false, cityList: [], empData: new EmployeeData };
}
this.handleSave = this.handleSave.bind(this);
this.handleCancel = this.handleCancel.bind(this);
}
public render() {
let contents = this.state.loading
? <p>Loading...</p>
: this.renderCreateForm(this.state.cityList);
return <div>
<h1>{this.state.title}</h1>
<h3>Employee</h3>
<hr />
{contents}
</div>;
}
private handleSave(event) {
event.preventDefault();
const data = new FormData(event.target);
if (this.state.empData.employeeId) {
fetch('api/Employee/Edit', {
method: 'PUT',
body: data,
}).then((response) => response.json())
.then((responseJson) => {
this.props.history.push("/fetchemployee");
})
}
else {
fetch('api/Employee/Create', {
method: 'POST',
body: data,
}).then((response) => response.json())
.then((responseJson) => {
this.props.history.push("/fetchemployee");
})
}
}
private handleCancel(e) {
e.preventDefault();
this.props.history.push("/fetchemployee");
}
private renderCreateForm(cityList: Array<any>) {
return (
<form onSubmit={this.handleSave} >
<div className="form-group row" >
<input type="hidden" name="employeeId" value={this.state.empData.employeeId} />
</div>
< div className="form-group row" >
<label className=" control-label col-md-12" htmlFor="Name">Name</label>
<div className="col-md-4">
<input className="form-control" type="text" name="name" defaultValue={this.state.empData.name} required />
</div>
</div >
<div className="form-group row">
<label className="control-label col-md-12" htmlFor="Gender">Gender</label>
<div className="col-md-4">
<select className="form-control" data-val="true" name="gender" defaultValue={this.state.empData.gender} required>
<option value="">-- Select Gender --</option>
<option value="Male">Male</option>
<option value="Female">Female</option>
</select>
</div>
</div >
<div className="form-group row">
<label className="control-label col-md-12" htmlFor="Department" >Department</label>
<div className="col-md-4">
<input className="form-control" type="text" name="Department" defaultValue={this.state.empData.department} required />
</div>
</div>
<div className="form-group row">
<label className="control-label col-md-12" htmlFor="City">City</label>
<div className="col-md-4">
<select className="form-control" data-val="true" name="City" defaultValue={this.state.empData.city} required>
<option value="">-- Select City --</option>
{cityList.map(city =>
<option key={city.cityId} value={city.cityName}>{city.cityName}</option>
)}
</select>
</div>
</div >
<div className="form-group">
<button type="submit" className="btn btn-default">Save</button>
<button className="btn" onClick={this.handleCancel}>Cancel</button>
</div >
</form >
)
}
}
Basically all the Get Api methods are being called but not the put or post methods, any help would be very very helpful, thanks in advance
modified 25-Dec-18 19:04pm.
|
|
|
|
|