Hide div if database contains value - Angular [closed] - javascript

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 6 years ago.
Improve this question
I want to check if a MySQL database contains a specific value. If it is true I want to hide a HTML <div>. Is this possible?
Can I hide elements with CSS & JS, or what should I use to hide the div?
Also, How would we add it in the Div like a NgIF statement
Thanks!

If you are seriously thinking about hiding the element with JavaScript (due to some kind of restriction or requirement). You can use following method.
CSS + Javascript + PHP way:
If you are thinking more like the Run code snippet section in Stack Overflow. Show expanded ONLY if it is set in database.
Then in that case you can implement something like this
$(function() {
$("#btnToggle").on("click", function() {
$("#comments").toggleClass("hide");
});
});
.hide {
display: none;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<!-- Hide using CSS way. Hide class can be echoed from your PHP based on the database value -->
<button type="button" id="btnToggle">Toggle hide/show</button>
<div id="comments" class="hide">Comment section to hide</div>

Try something like this in your PHP file. I have included an example of an item that is always rendered, and something that is conditionally rendered.
<div id="userinfo">
<?php // This is always rendered by the server ?>
Username: <?php htmlentities($row['username']) ?>
<?php // This is rendered by the server if the column is true ?>
<?php if ($row['admin']): ?>
<div class="admin">(admin)</div>
<?php endif ?>
</div>

Something along the line of
if (your statement condition) {
echo '<script type="text/javascript">document.getElementById(DIV_ID").style.display= "none";</script>';
exit;
}

Related

How to Embedded JQuery code in a php variable? [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
I want to embedded the below jquery code in the following php variable $var
JQUERY Code:
<img src="images/image.png" id="Image1" alt="" style="width:30px;height:30px;">
PHP Code:
<?php $var = 'my_jquery_code'; return $var; ?>
You just need to escape the single quotes:
<?php
$var ='<img src="images/image.png" id="Image1" alt="" style="width:30px;height:30px;">';
return $var;
The only reasonable scenario I can think of where you would want to use onclick would be if you're dynamically loading the anchor element.
If so, this is probably better.
[script]
$(document).on('click', '.my_class_here', function() {
$('jQueryDialog1').dialog('open');
});
[/script]
[link_template]
...
[/link_template]
Then you would use AJAX or whatever voodoo you like to retrieve the link template (maybe while passing it some variables?) and add it to the page.
Alternatively, you can use $(document).find('.my_class_here').on('click', function... , but this is bad, performance wise.

How on one click another page div value change 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
I have two page page1.php, page2.php and one JS file Control.js.
In page1.php
HTML :
<img src="images/b.jpg" width="31" height="26" id="imgClick1" onClick="return changeImage1(this)" >
In Control.js
function changeImage1() {
document.getElementById("imgClick1").src = "images/b.jpg";
document.getElementById('num1').style.color = "#fff";
document.getElementById("text1").innerHTML = "Hello friend";
}
In page2.php
<div id="text1">
Hello world
</div>
So using JavaScript I am trying to write "hello friend" in the div "text1" of page page2.php when I click the image or the div of page1.php.
Is there any possible way to use JS to solve this problem?
Can we use any how document.getElementById("text1").innerHTML or something like that in the program?
I suggest you make use of the include function of php (provided you absolutely want to keep your text1 div on a separate page), like this on your page1.php file:
include('page2.php');
Make sure that when you do that, page1.php and page2.php are in the same folder, otherwise you may define a path to it like this:
include('/path/to/page2.php');

How to make an onclick div in php [closed]

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 8 years ago.
Improve this question
<script type="text/javascript">
function Invest()
{
alert("Mechanical /n Electrical /n Computer /n Civil");
}
function create()
{
alert("Graphic /n Interior /n Architecture");
}
function motivate()
{
alert("Business Administration /n Accounting and Finance");
}
</script>
The above code is my javascript code
<form action="main.html" method="post">
<?php
$v2 = $_GET['dropdown'];
if ($v2=="investigative" )
{
echo "<h3>It's recommended that you follow</h3><h2>Engineering School</h2>";
}
else if ($v2=="creative" )
echo "<h3>It's recommended that you follow</h3><h2>Arts School</h2>";
else if ($v2=="motivated" )
echo "<h3>It's recommended that you follow</h3><h2>Business School</h2>";
?>
What i want to do is to change my echo to a div onclick so it will call my function from javascript and show the information i have inside it.
Something like this
echo ""<div onclick=Invest();"<h3>It's recommended that you follow</h3><h2>Engineering School</h2>";
When I do that thought i get an error
Parse error: syntax error, unexpected 'onclick' (T_STRING), expecting ',' or ';' in C:\xampp\htdocs\MyProject\eval.php on line 35
What am I doing wrong and how to make that work? I am new at php :/
Not something like this echo ""<div onclick=Invest();...
You need to do it like this put div tag inside double quotes for onclick attribute open single quotes because double quotes are already opened
echo "<div onclick='Invest()'><h3>It's recommended that you follow</h3><h2>Engineering School</h2></div>";

How to dynamically insert a form [closed]

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 page in which i want a form to be dynamically inserted according to datalist value, without reloading the page
<form action='#' method='get'>
<input list="category" name="category">
<datalist id="category">
<option value="Home">
<option value="Car">
<option value="Mobile">
</datalist>
<input type="submit">
</form>
For example if a person select Home, so the Home form should be shown at the bottom of the data list.
Any one have an idea how to do it?
You have many options. You can insert them as a string using innerHTML
document.getElementById("id_here").append(string); //or innerHTML = string; where string = your code above!
Or you could take another route and dynamically assemble a form using createElement.
var x = document.createElement("form");
x.id = "derp";
document.body.idtoappendto.appendChild(x);
Try this,
I think this will be simple solution
$('#submit').click(function () {
var cat = $('#cat').val();
$('#'+cat).show();
});
Updated Fiddle
Create a html file which contains your form or multiple html files containing one form each and in the page where you want to display the form write some ajax request based on which page the user is and call the corresponding form file and get its html and display it where ever you want.
for example in home page you want homeform.html to be displayed then create homeform.html in the directory and in home.html write an ajax function which fetches the homeform.html and display it on your home.html page.
You can simply doing this using below code..
First of all set form id attribute with the same name of category value & initially hide all forms using style="display:none". Then
$("input[type='submit']").click(function () {
var category = $("input[name='category']").val();
$('#'+category).show();
});

How to get the value of a dropdown using jquery? [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
Questions concerning problems with code you've written must describe the specific problem — and include valid code to reproduce it — in the question itself. See SSCCE.org for guidance.
Closed 9 years ago.
Improve this question
I have a dropdown menu and a link in a table. What I want is to get the value of the dropdown menu that is being retrieve in a row.
<td><?php echo form_dropdown('status',array('Fine' => 'Fine', 'Disposable' => 'Disposable'),'','class="status" id="status"'); ?></td>
<td align="center">
<i class="icon-edit icon-large"></i>
<div id="return" style="float: left;">
<!--when this one is clicked I can get the value of the dropdown-->
<i class="icon-backward icon-large"></i>
</div>
How can I get the value of the dropdown When the link with the class of return is clicked? I've tried .closest() function but it returned undefined. Thanks!
Did you tried?
$(document).on('click', 'a.return', function() {
alert($(this).closest('tr').find('#status').val());
});
Note: Using elements with the same id is a bad practice and can give you problems along the road. Please consider to remove #status id from the elements and use a class when selecting the element.
Try this instead:
$(document).on('click', 'a.return', function() {
alert($(this).closest('tr').find('select.status').val());
});
Use :
$(".return").click(function({
selectedValue = $('select[name="status"]').val(); //using name tag
selectedValue = $('.status').val(); // using Class
selectedValue = $('#status').val(); // using Id
console.log(selectedValue);
}));

Categories