Convert HTML code into jquery or javascript? [closed] - javascript

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions asking for code must demonstrate a minimal understanding of the problem being solved. Include attempted solutions, why they didn't work, and the expected results. See also: Stack Overflow question checklist
Closed 9 years ago.
Improve this question
I have a code in HTML using Spring notation.
The code is:
<c:if test="${testCSV==true}">
<img src="images/icons/edit.png" width="25" height="25" />
</c:if>
I want to check this condition in jQuery, So the condition checks dynamically.
please help me.

Add this code in html where you want to edit button to show
<a id="edit" href="#" onclick="editCSV(${command.id})" rel="tooltip-top">
<img src = "images/icons/edit.png" width = "25" height = "25" />
</a>
js
if (test == true) {
$('#edit').show();
} else {
$('#edit').hide();
}
pass true
<script type="text/javascript">
var test =pagetype('<%=${testCSV}%>');
if (test == true) {
$('#edit').show();
} else {
$('#edit').hide();
}
</script>

You can use this:
<script type="text/javascript">
var x = ${testCSV};
// some other code
</script>
The browser will see it as:
<script type="text/javascript">
var x = true; // or false
// some other code
</script>
Then, do whatever you like with it.

Related

How to stop showing the webpage after entering wrong answers? [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 1 year ago.
Improve this question
I have one webpage ,when loading the page it asks some questions if all the questions are correct only then it displays the body part otherwise the question will not allow next question or it should not displays the body part , please help me to fix this issue...
<!DOCTYPE html>
<html>
<head>
<title>Special-Wishes </title>
<script>
let q1=prompt("what is your name...?"); //if the q1 answer is wrong it should not display the body content
if(q1 == "John" || "JOHN" ){
let q2=prompt("what's your nick name...?");
if(q2=="blabla"){
alert("welcome to the page");
}
}
</script>
</head>
<body>
<h1>My body section</h1>
</body>
The reason why it is still asking the next question is due to your if statement logic
if(q1 == "John" || "JOHN" ) should be if(q1 == "John" || q1 == "JOHN" )
An even easier way of doing this would be if(q1.toUpperCase() == "JOHN")
In order to not display the body, you want to either remove it, or make it hidden. This can be done in a else block after your if statement
Remove: document.body.remove();
Hide: document.body.style.display = "none";
Use document.body.style.display = "none" when condition not matched
let q1 = prompt("what is your name...?"); //if the q1 answer is wrong it should not display the body content
if (q1 == "John") {
let q2 = prompt("what's your nick name...?");
if (q2 == "blabla") {
alert("welcome to the page");
} else {
document.body.style.display = "none"
}
} else {
document.body.style.display = "none"
}
<body>
<h1>My body section</h1>
</body>

i need help please check if anything is wrong with the program and please help me correct it [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 4 years ago.
Improve this question
<!Doctype html>
<html>
<title>JavaScript Tutorial</title>
<body>
<script language = "javascript">
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
if(cityToCheck === cleanCities[i]) {
alert("You are clean");
}
</script>
</body>
</html>
I cannot find the errors
it's a javascript code
<!Doctype html>
<html>
<title>JavaScript Tutorial</title>
<body>
<script language = "javascript">
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
if(cityToCheck === cleanCities[i]) {
alert("You are clean");
}
</script>
</body>
</html>
It says there is some problem in line 14
Where is your for loop for which you're an index i? If its removed intentionally then Tucson in your array has a space in the end. Use trim method.
Also language = "javascript" is wrong, its usually type="text/javascript"
The code should be like below:
enter code here
var cleanCities = ["Cheyenne ","Santa Fe ","Tucson ","Great Falls ","Honolulu"];
var cityToCheck = "Tucson";
for(var i=0; i<cleanCities.length; i++) {
if(cityToCheck === cleanCities[i].trim()){
alert('you are clean');
}
}

Date Comparison Angular JS [closed]

Closed. This question is not reproducible or was caused by typos. It is not currently accepting answers.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
Closed 4 years ago.
Improve this question
var discover = $filter("date")(new Date('08-24-2015'), "MM/dd/yyyy");
var occur = $filter("date")(new Date('06-07-2018'), "MM/dd/yyyy")
console.log(discover);
console.log(occur);
if (discover < occur) {
console.log('Discover less than occur');
} else {
console.log('No');
}
The result is always No to whatever value I assign to discover variable.
Did I compare it wrong?
I would advise you to use momentJS for date-time operations. It is much cleaner to implement.
To check if a certain time is before or after another time you could use their query functions
moment('2010-10-20').isBefore('2010-12-31', 'year'); // false
moment('2010-10-20').isBefore('2011-01-01', 'year'); // true
// Code goes here
var app = angular.module("app", []);
app.controller("BaseController", function($scope,$filter) {
var discover = $filter("date")(new Date('05-24-2015'), "MM/dd/yyyy");
var occur = $filter("date")(new Date('06-07-2018'), "MM/dd/yyyy")
console.log(discover);
console.log(occur);
if (discover < occur) {
console.log('Discover less than occur');
} else {
console.log('No');
}
});
<!DOCTYPE html>
<html>
<head>
<script data-require="angularjs#1.5.5" data-semver="1.5.5" src="https://code.angularjs.org/1.5.5/angular.js"></script>
<link rel="stylesheet" href="style.css" />
<script src="script.js"></script>
</head>
<body ng-app="app" ng-controller="BaseController">
</body>
</html>

insert input to form 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 7 years ago.
Improve this question
iam trying to post a file to database,i first created an empty form and then tried to add input using javascript,but i dont know how to link the newly created input to form and then submit hence the php shows no result.
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jqueryui/1.8.0/jquery-ui.min.js"></script>
<title>image upload</title>
<script>
function sub()
{
var form=document.getElementById('nform');
var fil1 = document.createElement("input");
fil1.setAttribute("type","file");
fil1.setAttribute("name", "image1");
fil1.setAttribute("value", document.getElementById('one1').value);
form.submit();
return
}
</script>
</head>
<body>
<form id="nform" action="http://mydomainname.net/somepost.php"method="post">
</form>
<input type='file' id="one1"/>
<input type="button" onclick="sub();" value="Submit">
</body>
</html>
PHP code:
<?php
$con = mysql_connect("mydomainname.net","489583788","39853953");
if (!$con)
{
die('Could not connect: ' . mysql_error());
}
mysql_select_db("489583788", $con);
echo $_FILES["image1"]["name"];
echo $_FILES["image2"]["name"];
echo $_FILES["image3"]["name"];
?>
Your input is out side of the form element, it wont be passed to action page. So you need to append it to the form and then submit. Use Node.appendChild().
function sub(){
var form=document.getElementById('nform');
var fil1 = document.createElement("input");
fil1.setAttribute("type","file");
fil1.setAttribute("name", "image1");
fil1.setAttribute("value", document.getElementById('one1').value);
fil1.setAttribute("style","display:none;");
form.appendChild(fil1);
form.submit();
return
}

How to access functions in javascript? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Closed 8 years ago.
This question was caused by a typo or a problem that can no longer be reproduced. While similar questions may be on-topic here, this one was resolved in a way less likely to help future readers.
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.
Improve this question
Code:
<html>
<body>
<script>
function mmm(x){
var val= [10,20,30];
return val;
}
</script>
<script>
function my(){
var va= mmm();
var b= va[1];
document.write(b);
}
</script>
</body>
</html>
there is a mistake in the above code, output is not generated. What I need is to display contents of 'val' of 'mmm(x)' function inside 'my()' function using document.write().
The two functions should be in different script tags. What are the changes do I need to make?
That's because you are not calling my function anywhere.
Try this.
<html>
<body>
<script>
function mmm(x){
var val= [10,20,30];
return val;
}
</script>
<script>
function my(){
var va= mmm(1);
var b= va[1];
document.write(b);
}
</script>
</body>
<button onclick="my()">click</button>
</html>
What I have done here I have a page having a button, and when you will click on that button, it will call that my function, and you will get 20 on your page.
You are not calling the function my
<html>
<body>
<script type="text/javascript">
function mmm(x){
var val= [10,20,30];
return val;
}
</script>
<script type="text/javascript">
function my(){
var va= mmm();
var b= va[1];
document.write(b);
}
my();
</script>
</body>
</html>
Try this code:
<script>
function mmm(){ //unwanted parameter is removed
var val= [10,20,30];
return val;
}
</script>
<script>
function my(){
var va= mmm();
var b= va[1];
document.write(b);
}
my();//calling method here
</script>
DEMO

Categories

Resources