I am using a PHP script to write in an image.
Source: http://papermashup.com/demos/php-gd-image-and-text/
I want to hide the image and after clicking the "Update Image" button the generated image would then be displayed?
Using Jquery Hide(); , show() function to achieve the functionality.
If you can put a code snippet here it will help people to understand the problem more clearly
You need javascript for this.
Basically, php only runs once before the page is loaded, so it can't change the contents of the page after it's loaded.
You can either use document.InnerHTML (look it up) or jquery .load
You can do this by using jQuery like
Suppose your input button has id like clickme and image which you want to hide has id like hideme then bind a jQuery event to this.
$('#clickme').click(function(){
$('#hideme').hide();
});
Just include basic jQuery libraries to your page.
<div id="hidden_div" style="display:none">
<img src=<?=$filename;?>?id=<?=rand(0,1292938);?>" width="800" height='600'/>
</div>
<input name="submit" type="submit" class="btn btn-primary" value="Update Image" onclick="showHide()"/>
</form>
</div>
<script type="text/javascript">
function showHide() {
document.getElementById("hidden_div").style.display = "block";
}
</script>
I used this. Is working, but it shows generated image for just a sec, then it's refreshing.
Related
I have a button in my html form that I want it to take user to food.php when they click on it, I did this but it's not redirecting, Please help
<a href="food.php">
<button name="submit" type="button" id="food">Food - Equipment</button>
</a>
Try this:
<button>Food - Equipment</button>
Why use a button element inside a link tag? Why not just:
Food - Equipment
Try that and see if it fixes it.
A button is requested, not a link. Sometimes linked php files don't work as expected in some browsers. Use a form submit button and you'll get what you're looking for.
<form action="food.php" method="GET"> <!-- use get or post if you want
to send anything -->
<input type="submit" value="GO">
</form>
I have created a wall like this in facebook using php and jquery. There is a textarea and an input type=button, and using jquery when the user posts something it is displayed under the text area without renew the page. I want to enable my script using an image loader named "loader.gif", so that after press submit button the loader start working until the new post appear. Any idea hot to do this?
<?php
<textarea rows="3" id="comment_text" placeholder="share an update..." style="font-size:11pt; color:#363636; resize:none; "> </textarea>
<input type="button" id="comment_process" style=""/>
?>
You want to place the loader image where it should ultimately be, but with display:none; in its CSS. Then, when the form is submitted, simply toggle it on.
HTML
<img class='loader' src='images/loader.gif' style='display:none;' />
jQuery
$('form').submit(function(){
$('.loader').show();
});
If you are submitting the form using ajax, you may need to hide it again if a success/error is returned. If you are doing a true form submission, the page will load to a different location anyway and there is no need to re-hide the image.
I want to submit a form to the database and I want to use a sprite image instead of regular submit buttons..
Here is the images I'm using
<div class="cancel">
</div>
<div class="save_and_new">
</div>
<div class="save_and_quit">
</div>
if(isset(......)){
}
I have no idea what to put in the isset function ...
Do i need to set names to the images? or what?
You could just use
<input type="image src="/your/button/image/here.gif" />
instead of the images nested inside anchors.
The only problem would be that you can't directly sense which button exactly was pressed because <input type="image" /> does not post a value. If you really need multiple post buttons that also post a value:
<button name="button" value="action1"><img src="/your/image/here.gif" alt="action 1" /></button>
<button name="button" value="action2"><img src="/your/image/here.gif" alt="action 2" /></button>
You can do it in Jquery. Try this,
$("#save_and_new_btn").click(function() {
$("#form").submit();
});
#form is id of form
Generally, a form is submitted when the user presses a submit button. However, sometimes, you may need to submit the form programmatically using JavaScript.
JavaScript provides the form object that contains the submit() method. Use the ‘id’ of the form to get the form object.
For example, if the name of your form is ‘myform’, the JavaScript code for the submit call is:
document.forms["myform"].submit();
But, how to identify a form? Give an id attribute in the form tag
<form id='myform' action='formmail.pl'>
Here is the code to submit a form when a hyperlink is clicked:
<form name="myform" action="handle-data.php">
Search: <input type='text' name='query' />
Search
</form>
<script type="text/javascript">
function submitform()
{
document.myform.submit();
}
</script>
Source: How to Submit a Form Using JavaScript
You need to use javascript.
Find a form which has to be submitted. Then add actions to each elements. Whene they're clicked you are submitting (or canceling) form.
I'm trying to implement popup search window in a PHP project. I included JQuery and ColorBox & have managed to open the Search popup inline (using ColorBox plugin).
This is my code to open popup window
$(document).ready(function(){
$(".inline").colorbox({inline:true, transition:'none',speed:'10', close:'close', opacity:'0.6'});
});
Popup div has a separate <form> element to POST data.
<?php
if (isset($_POST['btnSearch']))
{
//Code to search data
}
?>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post"
enctype="multipart/form-data">
//Some Page Content
<div class="input"><input type="submit" name="btnSearch" Value="Search"
class="button"></div>
</form>
The problem is when I click the 'Search' button it POST the form but closes the popup. How can I retain popup window opened even after the button click?
AJAX is what you're looking for. jQuery has built in AJAX support which you can read about HERE
It's real easy to use so you shouldn't have any problems implementing it
I have an included page to the main index page, in the included page it has buttons to click on..i want to give these buttons a variable and when someone clicks on it, I can keep track of what button they selected in another page, which will show information for the selected button/variable...
Any ideas?
Well there is several ways to do this, but the main question is are you using a form button or a image button or a link or what?
Form:
HTML:
<form name="phpForm" action="myFile.php" method="get">
<input type="submit" name="button" value="1">
<input type="submit" name="button" value="2">
</form>
PHP:
<?PHP
echo $_GET["button"]; //either 1 or 2
?>
Image:
HTML:
<img src="whoo.png" />
<img src="hilarious.png" />
And the PHP above will also work with this.
You should really start reading a basic PHP tutorial.
Depending on what form is the method, you'll receive the variables in either $_POST or $_GET:
Use this code to find out
print_r($_GET);
print_r($_POST);
Welcome to web programming, this should get you started: http://www.w3schools.com/php/php_intro.asp
There are several ways of doing this you can either use GET, POST, or store the variable in a SESSION
I am assuming when user clicks the button it is directed to another page, if its true, then you can do a GET with http://yoursite.com/pageTo.php?data='hello' as the href that links to the button. Where pageTo.php would $_GET['data']
Insert the jquery code to try out the click counts:
$(document).ready(function(){
var count =0;
$('button').click(function(){
count = count +1;
$('#showcount').html('click count' + count);
return false;
});
});
and somewhere in your body make a div with id = ' showcount' to show the click counts.
Or you can then save the click count into a text file to look at...or whatever
I hope this give you some ideas...