Javascript does nothing [closed] - javascript

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
This following code do nothing .When i click button it should tell my how many guess computer has taken to find my given input. I am using Adobe Dreamweaver.What might be wrong ?
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Untitled Document</title>
</head>
<body>
<p> How many finger ? </p>
<p><input id="myNum" type="text"</p>
<button id="guess"> Mafia </button>
<script type="text/javascript">
document.getElementById('guess').onclick=function(){
var myNumber=document.getElementById('myNum').value;
var GotIt=False;
var NumOfGuess=0;
while(GotIt==False)
{
var guess=Math.random();
guess=guess*6;
guess=Math.floor(guess);
if(guess==myNumber)
{
GotIt==True;
alert("Got It");
alert("You took"+ NumOfGuess +"guess");
}
else
{
NumOfGuess+=1;
}
}
}
</script>
</body>
</html>

Plea check your browser console, you could see that you've some typo's like False/True they should be in lowercase format false/true, e.g:
var GotIt=False;
while(GotIt==Flase){
}
That should be :
var GotIt=false;
while(GotIt==false){
}
Hope this helps.

There is a typo. Replace Flase by false. You should also use === instead of == in your code, but that's secondary.

Related

Button on HTML calling a google script [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 2 years ago.
Improve this question
I have an code.gs that creates a menu that opens a sidebar with html.
My html is like that:
<!DOCTYPE html>
<html>
<head>
<base target="_top">
<link rel="stylesheet" href="https://ssl.gstatic.com/docs/script/css/add-ons1.css">
</head>
<body>
<button onclick='ativarFeedbacks()'>Feedback</button>
<div id="aviso">aaasaaa</div>
<script>
function callback(resposta) {
document.getElementById("aviso").innerHTML=resposta;
}
function ativarFeedbacks() {
google.script.run.withSuccessHandler(callback).escrever();
}
</script>
</body>
</html>
My code.gs is like this:
function onOpen(e) {
FormApp.getUi()
.createAddonMenu()
.addItem('Configurar feedbacks', 'showSidebar')
.addToUi();
}
function showSidebar() {
var ui = HtmlService.createHtmlOutputFromFile('teste2')
.setTitle('Feedback');
FormApp.getUi().showSidebar(ui);
}
function escrever(){
return "<h1> salve salve </h1>"
}
But, when I run onOpen, I open the sidebar and press the button, nothing happens. My innerHTML on id "aviso" doesn't change like nothing was returned by escrever(). I am not understanding this behavior. What should I do?
The function escrever() doesn't exist. Use this instead:
google.script.run.withSuccessHandler(callback).escreverFeedbacks();

How to send "HTML SELECT VALUE" to another webpage with ajax without refresh page [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Where is a problem ? . I want to send selected value to another webpage without refresh page. Than i try using ajax.
Here is all script (only one file) i want to send value 0,2,4 like parameter "t" to another web page. But function $.ajax didn't work. but after part with alert yes.
<!DOCTYPE html>
<html>
<head>
<title>jQuery With Example</title>
<script src="http://code.jquery.com/jquery-1.9.1.js" type="text/javascript"></script>
<script type="text/javascript">
$(function () {
$('.btnClick').click(function () {
$.ajax({
url:'http://ip adress:84/?t='+ $('.sendnumber').val(), //the page for example http://192.168.100.100:84/?t=2
type: 'POST',
});
alert('Value = ' + $('.sendnumber').val());
alert('Text = ' + $('.sendnumber option:selected').text());
});
})
</script>
</head>
<body>
<div>
<select class="sendnumber">
<option value="0">24</option>
<option value="2">25</option>
<option value="4">26</option>
</select>
<br /><br />
<input type="button" class="btnClick" value="Click" />
</div>
</body>
</html>
Please help me.
Thanks Hunt3r
Just noticed that your jquery selector is wrong for the option value, use this instead:
$('.sendnumber option:selected').val()
Without seeing the HTML it's hard to say, but remember that posting to a page on a different domain will require the appropriate CORS setting up, as this is a cross origin security setting

I have a local json file and i want to display its data in listbox [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Suppose I have following data in the json file and I want it to render in the same format in my control list box which is in my view file
{
"data" :[
{
"text" : "abc"
}
]
}
You might want to elaborate and maybe read a little, although something like this shows how you can get data out of the JSON response.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8" />
<title></title>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.2.0/jquery.min.js">
</script>
<script type="text/javascript">
$(function() {
$.getJSON( "http://yourserver/test.json", function( data ) {
alert (data["data"][0]["text"]);
});
});
</script>
</head>
<body>
</body>
</html>
If you jQuery or something similar there are plenty of tools to Parse and manipulate the JSON data.
The jQuery Docs should provide you with everything you need to know. If you are using PHP or something else there a tools for that too.
jQuery getJSON
use JSON.stringify() function which convert your object into string
var $data={
"data" :[
{
"text" : "abc"
}
]
}
var $str=JSON.stringify($data);
now assign $str string wherever you want

How to make a Go url bar in html+css [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
Im a noob at js, and I would like to make a go bar like at the top of browsers in html and js. It will go to the url in the box when the button is pressed nothing more, nothing less. Heres about what i want:
In javascript you just have to add an event listener in the "Go" button.
Then when you click the button, you just have to redirect the url according to the text field value.
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="text" id="field" />
<button id="myBtn">Go</button>
<script type="text/javascript">
document.getElementById("myBtn").addEventListener("click", function(){
var url = document.getElementById("field").value;
window.location.href = url;
// OR
window.open(url);
});
</script>
</body>
</html>
With this code, if you enter a value in the text field and click the button. The url will add your value at the end.
For example if you are testing on the url localhost/ and you enter "test", javascript will redirect you to localhost/test.
To redirect correctly you must write "http://" or "https://" at the beginning

How to show html result form a texterea [closed]

Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 7 years ago.
Improve this question
In a page of my web, I have a textarea to write html code. How to show this html result of this textarea into a other view under this texterea.
You are looking for a WYSIWYG for angular:
Angular WYSIWYG directive
textangular
angular-redactor
angular-froala
List provided here as well: http://ngmodules.org/tags/wysiwyg
<html>
<head>
<meta name="description" content="quick edit panel" />
<meta name="viewport" content="width=device-width">
<script src="http://ajax.googleapis.com/ajax/libs/jquery/2.0.2/jquery.min.js"></script>
</head>
<body>
<div class="prompt" contentEditable=true
style="padding:5px;
background-color:black;
height:28px;
color:white;
font-family:'courier new'">
write a html code <span style="background-color:blue;">here</span>
</div>
<div class="result">
write a html code <span style="background-color:blue;">here</span>
</div>
<script type="text/javascript">
$('.prompt').focus();
$('.prompt').keypress(function(event){
if ( event.which == 13 ) {
var resultado = $('.prompt').html();
console.log(resultado);
$('.result').append($('<div/>').html(resultado).text()+"<br>");
$('.prompt').html('');
$('.prompt').focus();
}
});
</script>
</body>
</html>

Categories

Resources