A anchor as submit button with value - php

This may seem like a duplicate question but I have googled and search stackoverflow how an a anchor tag would act like as a submit that would fit on the website that I am trying to do.
I have this code on my right panel navigation:
<div class="content clearfix">
<div class="left_column">
<div class="product_menu">
<? if($_SESSION['logged_in'] == 1) {
$customer_panel = '
<div class="customer_nav">
<h1 class="customer_nav_name">Hello ' . $_SESSION['fname'] . ',</h1>
<ul class="clearfix">
<li>View Profile</li>
<li>Update Information</li>
<li>
<!-- this is where i would like the signout button to act as a submit
i have left it plane to start from scratch -->
Sign Out
</li>
</ul>
</div>';
echo $customer_panel;
}?>
<h2><span>Product Categories</span></h2>
<ul id="prod_nav" class="clearfix">
<li class="top"><span>Processed Meat</span></li>
<li class="top"><span>Ready Made</span></li>
<li class="top"><span>Siomai & Siopao</span></li>
<li class="top"><span>English Pork Snacks</span></li>
</ul>
</div>
And here is my usual code when i use a submit button and not an anchor tag to make a POST method:
if(isset($_POST['signout'])) { // logout button
// Clear and destroy sessions and redirect user to home page url.
$_SESSION = array();
session_destroy();
// Redirect to where the site home page is located -- Eg: localhost
header('Location: http://localhost/');
}
I have read many of this questions but I don't know jQuery or how to achieve this using javascript.
I also tried using this solution:
<form id="signout" action="index.php" method="post">
Sign Out
<input type="hidden" name="signout" value="signout"/>
</form>
that I kinda found from here at stackoverflow.
The problem about this is that if I include the onclick="" , the whole page does not show. but if i remove it, the page comes back to normal. - it doesn't work inside an <li> element.
It might sound basic, but it would help me and other new starters to understand how to make it possible. Thank you very much. :)

Try this,
STEP 1 :
Put the following scripts in your html file.
<script type="text/javascript" src="http://code.jquery.com/jquery-1.9.0.min.js"></script>
<script type="text/javascript">
$(function() {
$('.signout-btn').click(function() {
$('#signout').submit();
});
})
</script>
STEP 2 :
Add an attribute class="signout-btn" to anchor tags, which you want to trigger the form submission.

Related

How to get response from div which is having link in another div

I am really tired for searching this can someone help me... help will be really appreciate.
My question is Suppose I have one div element eg.
<div name="div1" class="demo">
and I have some links in that div so my code will something like:
<div name="div1" class="demo">
<ul>
<li> <a>Example1</a></li>
<li> <a> Example2</a></li>
</div>
and I have another div element which is
<div name="div2" class="demo2"> </div>
and I Now what i want, when i will click the link in first div eg. Example1.. I want the response of that link into div no 2 . IE on the another div which is
<div name="div2" class="demo2">
This is provided in html, for instance
<div id="name">
<ul>
<li> <a href="yourpage.html#name2" > Example1 </a> </li>
<li> <a> Example2 </a></li>
</ul>
</div>
Then in your reference div ensure you have given it the referring id, for instance
<div id="name2" class="demo2"> </div>
When you click on first link it should bring up the div with the id requested. Of course styling effects such as z-index can be added.
To be frank, you question is not understandable, However I am relating "Response" to "HTML" and "Link" to "Element".
So, Onclick of demo the content of demo will be moved to demo2.
Use JQUERY,
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
$(".demo").on("click", function(e){
$(".demo2").html($(this).html());
});

Putting Two Actions on one link using the Zend Framework

I'm new to the Zend framework and am trying to prevent my application from loading all of the necessary data at once and to wait until a button press. However, I want to be able to toggle between the pages instead of loading a new page. For instance, right now I have
<li>Families</li
This will toggle to the proper page and show the heading that I want it to. However, it will not get the data. I added a second button
<li>Families</li>
This button gets the data, but it redirects to the index tab, not to the #families tab. So I get the proper behavior if I click the second button (which get's the data), then the first button (which moves to the proper tab). How can I combine these into one?
I think you want to doing something like this ?
https://jsfiddle.net/mmfansler/2eTSL/
<ul class="nav nav-tabs tabs-up" id="friends">
<li> Contacts </li>
<li> Friends list</li>
<li>Awaiting request</li>
</ul>
<div class="tab-content">
<div class="tab-pane active" id="contacts">
</div>
<div class="tab-pane" id="friends_list">
</div>
<div class="tab-pane urlbox span8" id="awaiting_request">
</div>
</div>
With Javascript :
$('[data-toggle="tabajax"]').click(function(e) {
var $this = $(this),
loadurl = $this.attr('href'),
targ = $this.attr('data-target');
$.get(loadurl, function(data) {
$(targ).html(data);
});
$this.tab('show');
return false;
});

Add eventlistner dynamically using Jquery Ajax with dynamic page of laravel

I have divided my page in two parts. At left I am echoing All results with link and at right I want to display the result by clicking any link any time using Jquery Ajax.
My Blade code is ...
<div id="left" >
<ul>
#foreach($url_data as $url)
<input type="hidden" name="url_hits_id" value="{{url('dashboard'.'/'.$url->id)}}">
<li>
<a class="show_hits">
<p>{{$url->url}} </p>
<p> {{'http//ucut.herokuapps.com/'.$url->key}}</p><br><hr>
</a>
</li>
#endforeach
</ul>
<div id ="right" style="float:left">
</div>
My Jquery code is ....
$(document).ready(function(){
var url = $('input[name=url_hits_id]').val();
$('.show_hits').click(function(){
$.get(url,function(response){
$('#right').html(response);
});
});
});
I want to display the result via ajax. I have one problem with my selector. It is only showing the result of the first <li> element, not all....I also want that at clicking anytime at any <li> tag I want the result of every tag. I have checked the all page individually (without Ajax). All are working fine.
Change your blade like this:
#foreach($url_data as $url)
<input type="hidden" value="{{url('dashboard'.'/'.$url->id)}}">
<li>
<a class="show_hits" onclick="submit({{url('dashboard'.'/'.$url->id)}});">
<p>{{$url->url}} </p>
<p> {{'http//ucut.herokuapps.com/'.$url->key}}</p><br><hr>
</a>
</li>
#endforeach
<div id ="right" style="float:left"></div>
Then in your Js:
$(document).ready(function(){
function submit(url){
$.get(url,function(response){
$('#right').html(response);
});
}
});
I didn't test it but I think it should work.
Let me know if it works :)

slideToggle not working for me

Im trying to make a left side navigation that slides down with sub categories when you click on one of the links.
I've got it to work for the top link only but the others dont work.
In my header file I have some jquery script like this:
<script>
$(document).ready(function(){
$("#flip").click(function(){
$("#panel").slideToggle("slow");
});
});
</script>
in my HTML/PHP i have this code:
<div id="left-prod-nav">
<ul>
<li class="top">Product Categories</li>
<?for($i = 0; $i < $count; $i++)
{?>
<div id="flip"><li><img src="images/arrowright_off.gif" style="padding:0px; margin:0px;float:right;"><?=$result[$i]['categoryName']?></li> </div>
<div id="panel">Hello world!</div>
<?}?>
</ul>
<div class="clear"> </div>
</div>
so the navigation is there...and when I click on the top one, the others slide down so you can see the sub categories for the one I clicked.
however if I click any of the others nothing happens.
has anyone had this problem before or know how to solve it looking at my code?
Thanks
I can assume you are trying to accomplish something like this: http://jsfiddle.net/QQRy8/
$(".flip").click(function(){
$(this).next(".panel").slideToggle("slow");
});
I changed your jQuery to use classes, you should change your PHP to give each div a class name instead of an ID (ID's must be unique!)
This answer is based off this HTML:
<div class="flip">
<li>
cool
</li>
</div>
<div class="panel" style="display: none;">Hello world!</div>

List of submits in jQuery Mobile menu

I'm using a form with multiple submits to detect which button is clicked, but the list does not appear properly in a jQuery Mobile menu. I want it to appear nicely like in the JQM docs (click the "Menu" button), but it instead appears like in this picture. (In case it isn't obvious, the black boxes were me editing the names out.) What do I need to do to get it to collapse the submit buttons into a nice list like in the docs?
Navigate to different section
<div data-role="popup" id="navmenu">
<form name="navmenuform" action="X.php" method="post">
<ul data-role="listview" data-inset="true">
<li data-role="divider">Navigate to:</li>
<?php foreach ($array as $category) { ?>
<li><input type="submit" name="nav<?php echo $category[0]; ?>" value="Section <?php echo $category[0] . ": " . $category[1]; ?>"></li>
<?php } ?>
</ul>
</form>
</div>
The short answer is don't put submit buttons (at least visible) in listview items.
The problem is that buttons and lisview item's content area have their styling padding, margin, border, etc. Instead of fighting with styling you can just leverage what jQM gives you.
IMHO the simplest way to achieve what you want, if you can live with GET instead of POST, is to ditch the form and populate list items with anchors that href to appropriate urls with parameters and use rel="external" like this:
<div data-role="popup" id="navmenu" style="min-width:210px;">
<ul data-role="listview" data-inset="true">
<li data-role="divider">Navigate to:</li>
<li><a rel="external" href="X.php?nav1=Section 1:1">Section 1:1</a></li>
<li><a rel="external" href="X.php?nav2=Section 1:2">Section 1:2</a></li>
<li><a rel="external" href="X.php?nav3=Section 1:3">Section 1:3</a></li>
<li><a rel="external" href="X.php?nav4=Section 1:4">Section 1:4</a></li>
</ul>
</div>
If you want to be able to POST your form you can utilize a hidden input and a bit of JS code.
Given that you'll produce the following markup:
<div data-role="popup" id="navmenu" style="min-width:210px;">
<form name="navmenuform" action="X.php" method="post" data-ajax="false">
<ul data-role="listview" data-inset="true">
<li data-role="divider">Navigate to:</li>
<li>Section 1:1</li>
<li>Section 1:2</li>
<li>Section 1:3</li>
<li>Section 1:4</li>
</ul>
<input id="param" type="hidden" name="" value="">
</form>
</div>
Don't forget to put data-ajax="false" on your form tag, otherwise jQM by default will try to submit the form via ajax.
You then use click event on a list item, change name and value in your hidden input and submit the form:
$(document).on("pageinit", "#page1", function(){
$("#navmenu ul li a").click(function(e){
//Prevent default behavior since we need to submit the form instead of following the link
e.preventDefault();
//Change name and value attributes in out hidden input
$("#param").attr("name", $(this).attr("href")).val($(this).text());
//Submit the form
$("form[name=navmenuform]").submit();
});
});
Here is jsFiddle

Categories