javascript-events

Using custom data-attributes in html in onchange event

人走茶凉 提交于 2019-12-25 00:03:35
问题 The code below gives me an error "Fieldname not defined" when I am defining data-attributes and using them as parameters in a function. The update_person.php is updating a record in a database using the attributes in the input field. Is there a way to work around this? <!DOCTYPE html> <html> <head> <script> function update_person(str,fieldname,key,keyvalue) { if (str == "") { document.getElementById("txtHint").innerHTML = ""; return; } else { if (window.XMLHttpRequest) { // code for IE7+,

attaching listeners to body doesn't work?

 ̄綄美尐妖づ 提交于 2019-12-24 19:09:29
问题 I can't figure out why this piece of code isn't working: <!DOCTYPE html> <html><head></head><body onload=" document.body.addEventListener('mousedown',function(e){ alert(123); },false); "></body></html> There isn't even any error whatsoever.. it just does nothing. amazingly if i change 'mousedown' to 'keydown' it works <!DOCTYPE html> <html><head></head><body onload=" document.body.addEventListener('keydown',function(e){ alert(123); },false); "></body></html> (I'm using chrome btw) 回答1: The

Validating a text box value using javascript

随声附和 提交于 2019-12-24 19:06:30
问题 I have a textbox.The user will be entering entering a number in this box.The user should enter two digits followed by a period "." and another digit.It would look something like 22.3 or 00.5 or 01.2. If the textbox is not empty,I want to enforce a function which validates the value entered by the user(and gives them an alert if the value entered is not according to the format mentioned above) .This function needs to be triggered when the textbox loses its focus.I am not sure how to go ahead

Basic Calculator - event binding using pure javascript

不羁岁月 提交于 2019-12-24 17:53:08
问题 I am completely new to the Javascript .When I am looking to get the value to the button its get failed.I already given the setEvent.Like getEle(); And also bind the click function, Now i want to get the input values and perform mathematical calculations. <!DOCTYPE html> <html> <head> <title>Simple Calculator</title> <link rel="stylesheet" type="text/css" href="calculator.css"> </head> <body> <div id="container" > <div class="calculator"> <ul> <li> <div id="display"> <span id="math"></span>

d3js Text Transitioin - 1 example code not working

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-24 16:00:41
问题 I am new to d3.js and trying to execute some of the example codes given in the d3 examples. I tried copying the Text Transition-1 (link) example code. But came across this error in the console text-transition.html:26 Uncaught TypeError: d3.select(...).transition(...).duration(...).on is not a function Here is the code I executed: <!DOCTYPE html> <html> <head> <title>Text Transition animation 1</title> <meta charset="utf-8"> <style> h1 { font: 400 120px/500px "Helvetica Neue"; text-align:

flow based programing js html ui

给你一囗甜甜゛ 提交于 2019-12-24 15:34:40
问题 I need your great help on how to create a Simple Flow based UI in JS. For my simple structure I will have 3 node groups that will connect like so : Input -> Process -> output For the below example I would like to just start of with a static input value of x=65 that can be connected via a connector to a process of either x+10 or x+10000 and depending on which ever is selected the out put is shown. so its basically a function function input(){ x=65; return x; } function processadd10(x){ x=x+10;

Identify the attribute change event in KnockoutJS?

自古美人都是妖i 提交于 2019-12-24 15:25:03
问题 Is there any way to Identify the attribute change event in KnockoutJS?? I found solutions in jQuery: firing event on DOM attribute change firing event on DOM attribute change But It would be good If I can do it with KO. Thanks. 回答1: If the attribute change is bound to a property in your view model, then you can simply subscribe to that property to get notified of changes. myViewModel.myProperty.subscribe(function(newValue) { alert("This property changed!!"); }); 来源: https://stackoverflow.com

On browser close beforeunload - how to find if user selected “Stay” or “Leave”

谁都会走 提交于 2019-12-24 14:54:16
问题 To keep things very simple - I have the following code $(window).bind("beforeunload",function(event) { return ''; }) Atleast on Chrome,FireFox and IE9 - when a user closes the browser - he is presented with two options - "Stay on Page" or "Leave this Page" (The message varies from browser to browser) Now how can I find out what option the user selected For sake of simplicity - lets say - I want to show an extra message based on which option the user selected Something like - just to give an

pass e parameter, jQuery

瘦欲@ 提交于 2019-12-24 14:33:35
问题 I have the following code in my document ready: $('a').click(function(e) { e.preventDefault(); var $this = $(this); var horizontalPadding = 30; var verticalPadding = 30; $('<iframe id="externalSite" class="externalSite" src="' + this.href + '" />').dialog({ title: ($this.attr('title')) ? $this.attr('title') : 'External Site', autoOpen: true, width: 800, height: 500, modal: true, resizable: true, autoResize: true, overlay: { opacity: 0.5, background: "black" } }).width(800 - horizontalPadding)

Only run a JavaScript function if it is not run again after a set amount of time

我们两清 提交于 2019-12-24 12:25:55
问题 I have an input which controls the state of an element changing very rapidly. This causes that element to flicker as parts of it change. I am trying to store these state changes and then providing nothing has changed for a set amount of time (an arbitrary 500ms) change the state. I have tried to solve this using timeouts as demonstrated in the code below (the same code as in the fiddle.): var changingToHappy = false; // Original no attempts to fix functions. //var ifHappy = function () { // $