Jquery not submitting my form - php

Hi I want to submit my form using JQuery but I don't know why it won't work for me. here's the code:
$("#search_result_fake_div2").live("click", function () {
$("#search_result_present_list2").show("fast");
$('body').one('click',function() {
$("#search_result_present_list2").hide();
});
event.stopPropagation();
});
$(".search_result_list_item2").live("click", function () {
$("#search_result_fake2").val($(this).html());
$("#getattendees").submit();
$("#search_result_present_list2").hide();
});
and my HTML code:
<div>
<div id="search_result_fake_container">
<div id="search_result_fake_div2"></div>
<form method="GET" id="getattendees">
<input type="text" id="search_result_fake2" value="<?php if(!empty($city)){echo $city;} else{echo "Select Event";}?>" name="event_name">
</form>
</div>
<div id="search_result_present_list2">
<?php foreach ($events as $events1): ?>
<div class="search_result_list_item2" id="search_result_item_12" style="text-align:center;"><?php echo $events1['event_name']; ?></div>
<?php endforeach ?>
</div>
</div>
This is a drop down menu using div which came from my other question. One thing that I want to happen is for the form to submit once I've clicked a content from the drop down selection. I tried using onchange="javascript: document.getattendees.submit();" on my input box but nothing happens so I'm thinking of using jQuery instead but still the problem persists. I'm just a newbie on the jQuery and in fact I'm not that well versed on this one.

try this:
$('form#getattendees').trigger('submit');

Related

How Bootstrap modal get 'id' from url

I want to get 'id' from url and using in my Bootstrap modal.
How to get this '69'.In my modal i using this '69' with SQL request.
I Hope, your JS code is somehow similar to it.
<script>
$('.Contact').click(function(){
var id=$('.Contact').val();
$.ajax({url:"ModalPage.php?id="+id,cache:false,success:function(result){
$(".modal-content").html(result);
}});
});
</script>
In, ModalPage.php
<?
$id=$_GET['id'];
// Now, use this 'id'.
?>
an easy trick is to make hidden input inside modal code as below
<div id="myModal">
<form>
<input type="hidden" value="<?php echo isset($_GET['id']?$_GET['id']:''); ?>" /> <!--if you want to make it hidden-->
<label>ID = <?php echo isset($_GET['id']?$_GET['id']:''); ?></label><!--if you want to display-->
<!--your code-->
</form>
</div>

Javascript form submission doesn't give proper result

i have set the form action to a text retrieved from the database which has an id.my problem is when the form action executed it always shows the first id even if i clicked on the text holding id=2.I have checked the page source and it's showing the correct id for all the text.
here is my view code
<?php foreach ($content as $cont):?>
<form id="offer" method="post" action="<?php echo base_url() . 'index.php/pages/detail'?>">
<input type='hidden' name='cont_id'id='cont_id' value='<?php echo $cont->id?>'>
<a onclick="document.getElementById('offer').submit();"><?php echo $cont->title?></a>
</br>
</form>
<?php endforeach;?>
</div>
<script>
function submitForm() {
document.getElementById("offer").submit();}
</script>
here is my controller :
echo $this->input->post('cont_id');
You can use .submit()
Submit
If you have JAVASCRIPT knowledge you can use the
document.getElementById("myForm").submit();
method to submit the form..
create a Javascript Function
<script>
function submitForm()
{
document.getElementById("myForm").submit();
}
</script>
use this code for the text you want to hyperlink the button to
<h1 onclick="submitForm()">Click on this text</h1>

Change the value of 1 input into the value of another input on click

another JQuery question, I wanted to change the value of the hidden input based on the value of another hidden input. I'm having some trouble with this already. here's my code so far. This is not working but I think you can already get the idea of what I'm trying to do with this:
HTML code:
<div>
<div id="search_result_fake_container">
<div id="search_result_fake_div2"></div>
<form method="GET" id="getattendees">
<input type="text" id="search_result_fake2" value="<?php if(!empty($event_selected)){echo $event_selected;} else{echo "Select Event";}?>" name="event_name">
<input type="hidden" id="search_result_fake2_id" value="<?php if(!empty($event_selected)){echo $event_selected;} else{echo "0";}?>" name="event_id">
</form>
</div>
<div id="search_result_present_list2">
<?php foreach ($events as $events1): ?>
<div class="search_result_list_item2" id="search_result_item_12" style="text-align:center;"><?php echo $events1['event_name']; ?></div>
<input type="hidden" id="event_id" value="<?php echo $events1['event_id']; ?>">
<?php endforeach ?>
</div>
</div>
and the JQuery:
$("#search_result_fake_div2").live("click", function () {
$("#search_result_present_list2").show("fast");
$('body').one('click',function() {
$("#search_result_present_list2").hide();
});
event.stopPropagation();
});
$(".search_result_list_item2").live("click", function () {
$("#search_result_fake2").val($(this).html());
$("#search_result_fake2_id").val($("#event_id").val());
$("#getattendees").trigger('submit');
$("#search_result_present_list2").hide();
});
I use GET just to check if the values are moving and I'm not that sure if the line $("#search_result_fake2_id").val($("#event_id").val()); is really working.
Add the event parameter to your #search_result_fake_div2 click handler, like so:
("#search_result_fake_div2").live("click", function (event) {
^--------HERE
Because otherwise you will have a javascript runtime error when you try to use it later in:
event.stopPropagation();

PHP Pass variable to popup form within same page

Following on from a previous question, (previous question here), the problem I'm having seems to involve trying to pass/post a value through a form when the form action is '#'. I've tried session data but it always returns the last item from the database. Everthing else returns nothing.
Any help/ideas/advice greatly received, S. (Code below)
This is the code that displays the list of items, each containing an 'email' link/button to one instance of a popup window/form that is located at the bottom of the page.
<?php
$query = mysql_query("select * from istable where categoryID = '1'");
while ($result = mysql_fetch_array($query)) {
echo '<h4>'.$result['title'].'</h4>
<p>'.substr($result['descrip'],0,408).'... <strong>Read more</strong></p>
<form action="#" method="post" rel="#sheet" class="see">
<input type="hidden" name="propTitle" value="'.$propResult['title'].'">
<input type="submit" name="submit" value="Email">
</form>
';
}
?>
This is the code for the popup window/form at the bottom of the same page that is called through jquery.
<div id="sheet" class="rounded">
<!--{{{ pane1 -->
<div class="pane" id="pane1">
<h4>Email Details to a Friend</h4>
<p>You have selected to forward the details of <?php echo $_POST['propTitle']; ?> to a friend.</p>
<p>Please fill out the following form</p>
<form class="rounded" id="email-form" method="post" action="<?php echo $pageLink; ?>">
<!-- form goes in here -->
</form>
</div>
<!--}}}-->
</div>
<script type="text/javascript">
$(".see").overlay({mask: '#999', fixed: false}).bind("onBeforeClose", function(e) {
$(".error").hide();
});
</script>
Why are you using PHP for this? If the popup is called through the same page, use JavaScript to get the DOM element value and if you need to process data use AJAX.

Jquery form submit with PHP

I need help with what I thought would be a simple form submit problem with Jquery, but am running into issues.
I have a form, #listing_step_1, in which the user first selects a category from a dropdown. When a category has been selected, if the user clicks "next", the subcategory dropdown is revealed. When both a category and subcategory is selected, clicking next will take them to step 2 of the process using a redirect. On submission, the form is reloading the same page using $_SERVER['PHP_SELF'].
I want to autosubmit the form so clicking on next is not required to reveal the subcategories. I'm trying to do this on an onchange event using JQuery, but the following code does not work.
$('#item_category').change(function(){
$('#listing_step_1').submit();
});
I would appreciate any help with this as I am new to form submission using JQuery and AJAX. Manually, it's working fine - i.e., pressing the page button and with the PHP page refresh. I thought by simply submitting the form in the onchange instance it would reload and execute the required actions, but this does not appear to be the case.
Form code:
<form method="post" name="listing_step_1" id="listing_step_1" action="<?php $_SERVER['PHP_SELF'] ?>" enctype="multipart/form-data" <?php if($errormessage != ""){ echo ' style="margin-top: 30px"';}?>>
<div class="formField fullwidth">
<label for="item_category">Category *</label>
<select id="item_category" name="item_category">
<option value="0">Select category...</option>
<?php $cd = new CategoryListing("<option_credits>", "</option>"); ?>
</select>
</div>
<div class="formField fullwidth">
<label for="item_subcategory">Subcategory*</label>
<?php if($dropdownlist != "") { ?>
<select id="item_subcategory" name="item_subcategory">
<?php echo $dropdownlist; ?>
</select>
<?php } else { ?>
<select id="item_subcategory" name="item_subcategory" disabled="true">
<option value="0">Select subcategory...</option>
</select>
<?php } ?>
</div>
<input type="submit" value="Next" id="submit" name="submit" style="width: 100px;" />
</form>
Form Submission:
if(isset($_POST['submit'])){
if($_POST['item_category'] != 0){
$dropdownlist = CategoryListing::getSubCategoryDropdown($_POST['item_category']);
}
else {
$errormessage = "Please select a category";
}
}
Jquery:
$(document).ready(function(){
$('#item_category').change(function(){
this.form.submit();
});
});
Try this instead:
$(function() {
$('#item_category').change(function(){
this.form.submit();
});
});
in your description, you say:
I have a form, #listing_stage_1, in
which the user first selects a c...
then in code you say:
$('#item_category').change(function(){
$('#listing_step_1').submit();
});
I imagine you are just using the wrong selector... change your code to this:
$('#item_category').change(function(){
$('#listing_stage_1').submit();
});

Categories