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
Related
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 :)
I have to pass the id of selected tab when another action occurs
<ul class="nav nav-tabs" id="myTab">
<li <?php if($all_index== 1){?> class="active" <?}?> >All</li>
<li <?php if($select_index== 1){?> class="active" <?}?>>Selected</li>
<li <?php if($reject_index== 1){?> class="active" <?}?> >Rejected</li>
</ul>
I have a dropdown to filter the tab data..First tab is always active.
If i want to filter the second tab,then i click the dropdown the action occur..but the tab selected is first one..I want the Second one
If you are looking to capture the value on form submit, create a hidden field in your form. So every time on click, capture the id of the tab and store in hidden field.
<input type="hidden" id-"hidden" name="tab-selected" />
In script
$(document).on("click","#myTab a",function() {
var sel = $(this).attr("href");
$("#hidden").val(sel);
});
so on form post, you will get the selected tab's value.
Here is the fiddle demo
In View
<ul class="nav nav-tabs" id="myTab">
<li <?php if($tab_index== 1){?> class="active" <?}?> >All</li>
<li <?php if($tab_index== 2){?> class="active" <?}?>>Selected</li>
<li <?php if($tab_index== 3){?> class="active" <?}?> >Rejected</li>
</ul>
in Controller
public function FunctionName($value)
{
# code...
// pass which id should be active alone with data
}
I am currently using Bootstrap Timeline (example here). Since this will be a long timeline I want at the top of it to have some symbols (each with a date and a unique ID), which will represent certain event. When clicking a certain symbol I want to be redirect to the correspondent event on the timeline.
Nevertheless, at the moment, when I click the symbol I am redirected to the top of the div 'container' which contains the timeline and not to the specific <li>
Example:
LINK:
<ol class="timeline">
<li class="timeline__step done">
</li>
</ol>
TO:
<div class="container">
<ul class="timeline2">
<li id = "type1" onclick = "window.location.hash = 'type1';">
</li>
<ul>
<div>`
Remove id from the link and remove the onclick from the timeline item. The hashtag in href should jump to the id set in the timeline item.
<ol class="timeline">
<li class="timeline__step done">
</li>
</ol>
<div class="container">
<ul class="timeline2">
<li id="type1">
</li>
<ul>
<div>
Because you have the same id "type1" for two DOM elements. Id should be unique.
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.
I need a dynamic function for checking whether a radio box is selected in the div or not.
Actually I want to show an error message every time an user, without selecting the radio button, presses the next button.
I am working on this page. The ILERI means NEXT.
These are the divs. There are 9 div on the page cited above.
<div id="div2" class="targetDiv">
<a id="back" class="ileri-geri" target="1" >GERİ</a> <h1>Cep Çesitleri</h1>
<a class="ileri-geri" target="3">İLERİ</a>
<div class="urunler">
<ul class="urun">
<li><img src="imagesBOX/items/cepsayisi/0.jpg"></li>
<li><p>Cepsiz</p><input type="radio" name="cep_cesitleri" value="0" /></li>
<li></li>
</ul>
<ul class="urun">
<li><img src="imagesBOX/items/cepsayisi/1.jpg"></li>
<li><p>Tek Cepli</p><input type="radio" name="cep_cesitleri" value="1" /></li>
<li></li>
</ul>
<ul class="urun">
<li><img src="imagesBOX/items/cepsayisi/2.jpg"></li>
<li><p>Çift Cepli</p><input type="radio" name="cep_cesitleri" value="2" /></li>
<li></li>
</ul>
<h1>Cep Sayisi</h1><br/>
<?php foreach($Secondresult As $jcRow): ?>
<ul class="urun">
<li><img src="imagesBOX/items/cep_cesitleri/<?php echo $jcRow->image ?>" /></li>
<li><p><?php echo $jcRow->title ?></p><input type="radio" name="cep_cesitleri" value="<?php echo $jcRow->id ?>" /></li>
<li></li>
</ul>
<?php endforeach; ?>
</div>
</div>
<!----2nd page--->
this is javascript which hides all the div and show the div only based on target attribute of tag .
<script type="text/javascript">
$(document).ready(function(){
$('.targetDiv').hide();
$('#divfirst').show();
$(".ileri-geri").click(function(event){
$('.targetDiv').hide();
$('#div'+$(this).attr('target')).fadeIn('slow');
//alert("Redirecting you to jQuery.com!");
});
</script>
Now I want that, If user click on ILERI button without selecting the radio option, then the error mesg will appear, but the function should dynamically show that it handles all the 9 div on this page.
You can check if at least one item was checked with this:
$(".urun input:checked").length() > 0
$(".ileri-geri").click(function(event){
//you have to detect the visable .targetDiv first
if($('.targetDiv:visible input:checked').length() > 0) {
$('.targetDiv').hide();
$('#div'+$(this).attr('target')).fadeIn('slow');
}else{
alert("Error");
}
});