Create buttons dynamically in a div from a javascript function [closed] - javascript

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 9 years ago.
Improve this question
I have a function that returns the data from the sql...
I need to create buttons in a div called
divResult
here is my function
function retrieveData(transaction, results) {
for(var i = 0; i < results.rows.length; i++) {
var data = results.rows.item(i)['nome'];
alert(data);
}
}

There is a very good answer on how to create html elements using javascript here: Creating Dynamic button with click event in javascript.
...I would add this as a simple comment but I don't have enough street cred yet.

Related

How can I detect if user has successfully alerted a thing (I'm making an XSS game) [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
The page just echoes the user input using GET. I have no idea on what concept to apply to detect if the user has alerted something
The easiest approach would probably be to replace the alert method with your own.
const log = [];
alert = function(alert) {
return (value) => {
log.push(value);
alert(value);
};
}(alert);
alert("Hello!");
console.log(log);

How can I make a variable static in Js? [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 2 years ago.
Improve this question
I want the newid to be incremented when I call the function.
You make the function close over the variable, by declaring the variable in the surrounding context:
let newid = 3;
const generateTemplate = contact => {
// ...
newid++;
};

How to generate set strings in javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 3 years ago.
Improve this question
Trying to generate a set of strings such as 'TCP', 'DNS' or 'SQL'
I want to be able to have these strings set and be able to have them appear randomly like you would with random numbers.
You can make an array and select them randomly:
const strings = ['TCP', 'DNS', 'SQL'];
for (var i = 0; i < 5; i++) {
console.log(`Random string: ${strings[Math.floor(Math.random() * strings.length)]}`);
}

How to make the following JavaScript code work and result in a list of names and ages inside the element with ID "myDivId" : [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to make the following JavaScript code work and result in a list
of names and ages inside the element with ID "myDivId" :
<div id="myDivId">No results yet</div>
<script>
new PersonPrinter("myDivId",[{"name":"Joe","age":"23"}
{"name":"Sam","age":"31"}]).render();
</script>`
In the PersonPrinter render function you need to update the div
PersonPrinter.prototype.render = function(id,data) {
var elem = document.elementById(id);
for (var i =0;i <data.length;i++) {
var d = dcoument.createElement('div');
d.appendChild(document.createTextNode('Name'+data.name +' Age:'+data.age');
elem.appendChild(d);`enter code here`
}
}
You need to access div id using innerHTML
var a = Document.getElementById('myDinId');
And for changing value use simply = operator
a.innerHTML = 'Something';

Show results of multiple prompt boxes using Javascript [closed]

Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 years ago.
Improve this question
How to make multiple prompt boxes and sort their input alphabetically and then show on screen using JavaScript ?
Thanks
Sequentially
if you are talking about the almost obsolete native javascrtipt function prompt() then:
var array=[];questions=['A?','B?','C?'],current=0;
function q(question){
array.push(prompt(question,'write here')+' question number:'+current);
if(current<questions.length){
next()
}else{
array.sort()// needs a proper sort function
alert(array.join("\n"));
};
}
function next(){
q(questions[current++]);
}
next();
Demo
http://jsfiddle.net/c7GnX/

Categories

Resources