<script type="text/javascript">
$('.show_edit').click(function() {
$(this).hide();
$(this).siblings('.edit_faq').show();
$(this).parent().prev().find('.remove_att').removeAttr( "readonly" ); // this working perfect
$(this).next().find('.remove_text').removeAttr( "readonly" ); // this is not working
});
</script>
<?php foreach ($faq as $faq): ?>
<div class="form-group">
<label class="col-sm-2 control-label">Question : </label>
<div class="col-sm-8">
<input type="text" id="question" class="form-control remove_att" value="<?php echo $faq['faq_question'] ?>" placeholder="Enter the question" readonly="readonly" required="">
</div>
<div class="col-sm-2" class="edit_all">
<button type="button" class="btn btn-warning btn-sm show_edit" data-toggle="tooltip" data-placement="bottom" title="Edit"><i class="fa fa-edit"></i></button>
<button type="button" id="<?php echo $faq['faq_id'] ?>" class="btn btn-success btn-sm edit_faq" data-toggle="tooltip" data-placement="bottom" title="Save" style="display: none"><i class="fa fa-floppy-o" ></i></button>
<button type="button" class="btn btn-danger btn-sm delete_faq" id="<?php echo $faq['faq_id'] ?>" data-toggle="tooltip" data-placement="bottom" title="Delete"><i class="fa fa-trash"></i> Delete</button>
</div>
</div>
<div class="form-group">
<label class="col-sm-2 control-label">Answer : </label>
<div class="col-sm-8">
<textarea class="form-control remove_text" id="answer" rows="5" placeholder="Type your answer..." required="required" readonly ><?php echo $faq['faq_answer'] ?></textarea>
</div>
</div>
<?php endforeach; ?>
i'm doing inline edit using save and edit button with the help of jquery.
when i click on edit button input type="text" and textarea remove the readonly attribute. where input type="text" is working correctly,now i want to remove the readonly from textarea how to do this, any help would be appreciated
Your .show_edit button wrapped in 2 divs:
div.edit_all and div.form-group
And, your textarea is located in the next div.form-group,
So, try this:
$('.show_edit').click(function() {
$(this).hide();
$(this).siblings('.edit_faq').show();
$(this).parent().prev().find('.remove_att').removeAttr( "readonly" );
$(this).closest('.form-group').next().find('.remove_text').removeAttr( "readonly" );
// ^find the closest div.form-group parent
});
You can find parent of .show_edit then again find its parent.
Your textarea is present in next div where we find .remove_text class for remove readonly
so try this :
<script type="text/javascript">
jQuery(document).ready(function(){
$('.show_edit').click(function() {
$(this).hide();
$(this).siblings('.edit_faq').show();
$(this).parent().prev().find('.remove_att').removeAttr( "readonly" );
$(this).parent().parent().next().find('.remove_text').removeAttr( "readonly" );
})
});
</script>
Related
I have a set of form fields in PHP. I also added jQuery functionality to clone some fields and add them to the form. However, after I submit the form only the original fields are submitted and not the ones added though cloning.
PHP
<form id="myForm" method="post" action"...">
<div class="row contRow">
<div class="col-md-5">
<input type="text" id="contactInputName['.$i.']" name="name['.$i.']" value="'.$output['0'].'" class="form-control" placeholder="Name">
</div>
<div class="col-md-6">
<input type="text" id="contactInputEmail['.$i.']" name="email['.$i.']" value="'.trim($output['1']).'" class="emlVal form-control">
</div>
<div class="col-md-1 text-right">
<span class="btn btn-default rmContact"><i class="fas fa-times fa-fw fa-lg text-danger"></i></span>
</div>
</div>
<div class="row">
<div class="col-md-12">
<span id="saveContacts" class="btn btn-success"><i class="fas fa-check fa-fw fa-lg"></i> Save Contacts</span>
<span id="addRow" class="btn btn-default"><i class="fas fa-plus-circle fa-fw fa-lg"></i> Add More</span>
</div>
</div>
</form>
JS
$(document).on("click", "#addRow", function() {
var lastRow = $("#addContactsForm").find(".contRow").last();
lastRow.clone().insertAfter(lastRow);
lastRow.find("input").val("");
});
$(document).on("click", "#saveContacts", function() {
$(this).closest("form").submit();
});
What am I missing?
I would remove id="contactInputName['.$i.']" and id="contactInputEmail['.$i.']" because I don't see the need to set these attributes.
If you set name attributes with empty keys, incremented keys will be generated for you. E.g.
name="name[]"
and
name="email[]"
This should eliminate the issue with copied indexes while cloning.
i have following div in project. after clicking on "request for demo" button , it will redirect to next window to registration form (link is mentioned in javascript function). i want to save relevant div id in database after clicking on button and save register.
following is my html and javascript
<div class="row">
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Supermarkets, Fruits & Vegetables</b></span>
<hr>
<p>Uninterrupted fast billing, inventory control, CRM & Loyalty programs makes your shoppers happier</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<!--<button type="button" onclick="openWin()" class="btn btn-default" id="demo-btn" data-toggle="modal" data-target="#demoModal">Request for Demo</button>-->
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Supermarkets, Fruits and Vegetables" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Grocery & Departmental Stores</b></span>
<hr>
<p>POS for grocery, departmental store, hypermarket and convenience store with GSmartPOS</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Grocery and Departmental Stores" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Pharmacy, Medical Shop POS</b></span>
<hr>
<p>Prefilled drug index, update stock position and bill from Day One. Manage batches and expiry with ease</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Pharmacy Medical Shop POS" >Request for Demo</button>
</div>
<br>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Apparel & Footwear</b></span>
<hr>
<p>POS Features like matrix-inventory, non-moving stock analysis, can help keep inventory latest and fashionable</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Apparel and Footwear" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Electrical & Electronics POS</b></span>
<hr>
<p>Perfect solution to manage serialized inventory for mobile, computer electrical and electronics shops</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Electrical and Electronics POS" >Request for Demo</button>
</div>
<div class="col-md-4 col-sm-6 pos-vertical">
<span><b>Fashion Jewellery Shop</b></span>
<hr>
<p>An integrated, modular & scalable POS for furniture, glass & crockeries, opticals, music, toys & baby shop retail</p>
<button type="button" class="btn btn-default" id="dwmld-btn">Free Download</button>
<button type="button" onclick="openWin()" class="modalBtn btn btn-default" id="Fashion Jewellery Shop" >Request for Demo</button>
</div>
</div>
following function is called on each div button,
<script>
function openWin() {
window.open("register.php");
}
</script>
after clicking on each div button following form will be open in new window,
<div class="register">
<div class="container">
<div class="row main">
<div class="main-register main-center">
<form class="" method="post" id="contact-form">
<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon" id="register-icon"><i class="fa fa-user fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" id="name" placeholder="Enter your Name"/>
</div>
</div>
</div>
<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon" id="register-icon"><i class="fa fa-envelope fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" id="email" placeholder="Enter your Email"/>
</div>
</div>
</div>
<div class="form-group">
<div class="cols-sm-10">
<div class="input-group">
<span class="input-group-addon" id="register-icon"><i class="fa fa-phone fa" aria-hidden="true"></i></span>
<input type="text" class="form-control" id="contact_no" placeholder="Enter your contact number"/>
</div>
</div>
</div>
<input type="hidden" id="requestType">
<div class="form-group ">
<button class="btn btn-primary btn-lg btn-block register-button submit">Register</a>
</div>
</form>
<span class="success" style="display:none">Thank You for Register with us.</span>
</div>
</div>
</div>
</div>
form will be save using ajax and php
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.3.0/jquery.min.js"></script>
<script type="text/javascript" >
$(function() {
$(".modalBtn").click(function(){
var formName = $(this).attr("id");
$('#requestType').val(formName);
$('.success').hide();
$('.error').hide();
$('#contact-form').show();
$("#demoModal").modal();
});
$(".submit").click(function() {
var name = $("#name").val();
var requestType = $('#requestType').val();
var contact_no = $("#contact_no").val();
var email = $("#email").val();
//alert(requestType);
var dataString = 'name='+ name + '&contact_no=' + contact_no + '&email=' + email+ '&requestType=' + requestType;
if(name=='' || contact_no=='' || email=='')
{
$('.success').fadeOut(200).hide();
$('.error').show();
}
else
{
$.ajax({
type: "POST",
url: "register.php",
data: dataString,
success: function(){
$('.success').fadeIn(200).show();
$('.error').fadeOut(200).hide();
$('#contact-form').hide();
}
});
}
return false;
});
});
</script>
Php code to insert data is,
<?php
require('connection.php');
if($_POST) {
$id = $_POST['regid'];
$name = $_POST['name'];
$contact_no = $_POST['contact_no'];
$email = $_POST['email'];
$requestType = $_POST['requestType'];
if ($id == '') {
$sql = "INSERT INTO registration(name,contact_no,email,requestType) VALUES ".
"('".$name."', '".$contact_no."', '".$email."','".$requestType."')";
}
$query_result = mysql_query( $sql );
if(!$query_result ) {
echo 'Could not enter data: ' . mysql_error();
} else {
//header("Location: lead-view.php?s=Y");
$successMsg = 'Record instered successfully';
}
}
?>
i want save those div id as in url after submitting form of relevant dive click button. url will be save in "requestType" field in database. please help.
You can make use of sessionStorage for passing the requestType value.
https://www.nczonline.net/blog/2009/07/21/introduction-to-sessionstorage/
While calling openWin() pass the div value to it. For example:
<button type="button" onclick="openWin('abc')" class="modalBtn btn btn-default" id="Supermarkets, Fruits and Vegetables" >Request for Demo</button>
Then save this value in sessionStorage as follows:
function openWin(div_value) {
sessionStorage.setItem("registerType", div_value);
window.open("register.php");
}
You can retrieve this variable in register.php:
var registerType = sessionStorage.getItem("registerType");
Add this value to the hidden input control in register form and save it to database.
<input type="hidden" id="requestType">
How can I pass with form what is selected from dropdown field? So that url goes to ?s=sdf&tag=bookor ?s=sdf&tag=newspaper in this example
http://codepen.io/filaret/pen/yazXKQ
I couldn't create my design goal with <select><option>... inside input element so I used Bootstrap dropdown with .input-group-btn.
<form action="<?php echo esc_url( home_url( '/' ) ); ?>">
<div class="input-group">
<input type="text">
// SELECT OPTIONS
<div class="input-group-btn">
<button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown"><i class="fa fa-book"></i></a></button>
<ul class="dropdown-menu">
<li><i class="fa fa-book"></i></li>
<li><i class="fa fa-newspaper-o"></i></li>
</ul>
</div>
// SUBMIT BUTTON
<div class="input-group-btn">
<button type="submit" class="btn btn-default" data-toggle="dropdown">Submit</button>
</div>
</div>
</form>
I managed to make it work with this
<input id="search-hidden" type="hidden" value="">
$selectWrapper.find(".dropdown-menu li").click(function() {
var $selectedIcon = $(this).find('.fa');
$selectWrapper.find("#search-hidden").val( $selectedIcon.data('value') );
});
I'd appreciate your help with this!
Here is my bootstrap HTML code:
<div class="form-group centered">
<input type="submit" class="btn btn-primary btn-block" name="login" value="Log In"></input>
</div>
<div class="centered">
<div class="form-group btn-group" data-toggle="buttons">
<label class="btn btn-default active">
<input type="radio" id="app" value="app" name="dashboard"/>Application
</label>
<label class="btn btn-default">
<input type="radio" id="setup" value="setup" name="dashboard"/>Setup
</label>
</div>
</div>
I would like to add some logic that after the "Log In" button is selected, the "active" class on the label is retained properly.
Example:
Setup is selected
The user clicks login
The password is wrong so the user is thrown back to the same log in form
This time the form has the setup button "active" automatically
I tried playing around with the following within the app input type:
<?php if($_POST['dashboard'] == "app") { echo checked="\"checked\""; } ?>
I now realize, however, that this button group does not work like a regular radio button, and I probably need to toggle the class on the labels somehow.
Thanks in advance for your help!
I got it working piggybacking on the advice of user1844933 :)
<div class="form-group centered">
<input type="submit" class="btn btn-primary btn-block" name="login" value="Log In"></input>
</div>
<div class="centered">
<div class="form-group btn-group" data-toggle="buttons">
<label class="btn btn-default <?php setAppDefault( $lastDashboardSetting ); ?>">
<input type="radio" value="app" name="dashboard"/>Application
</label>
<label class="btn btn-default <?php setSetupDefault( $lastDashboardSetting ); ?>">
<input type="radio" value="setup" name="dashboard"/>Setup
</label>
</div>
</div>
My PHP code:
$lastDashboardSetting = $_POST['dashboard'];
function setAppDefault( $setting ) {
if( $setting === "app" )
echo "active";
else
echo "";
}
function setSetupDefault( $setting ) {
if( $setting === "setup" )
echo "active";
else
echo "";
}
try this
php
if($_POST['dashboard'] == "app" { $appchk='checked'; } else {$appchk='';}
if($_POST['dashboard'] == "setup" { $setupchk='checked'; } else {$setupchk='';}
HTML
<input type="radio" id="app" value="app" name="dashboard" <?php echo($appchk);?>/>Application
<input type="radio" id="setup" value="setup" name="dashboard" <?php echo($setupchk);?> />Setup
I'm using angular with a MySQL backend.
I think I'm missing something regarding ng-model.
When I click add new idea, nothing happens. Any ideas. I'd had it working, but then I changed some things, so I know it's registering to the database. Additionally, when it did work, it would only update without a refresh occasionally. My main goal is getting the adding working again, but if there's something else blatantly wrong, please feel free to give me a hard time.
thanks, all.
html
<form>
<div>
<input type="text" class="form-control" name="idea" ng-model="ideaInput">
<button class="btn btn" type="submit" ng-click="addIdea(ideaInput)">Add
New Idea</button>
</div>
</form>
php
<?php
require_once 'db.php'; // The mysql database connection script
if(isset($_GET['idea'])){
$task = $_GET['idea'];
$status = "0";
$created = time();
$query=mysql_query("INSERT INTO ideas(idea,status,created_at) VALUES ('$idea', '$status', '$created')") or die(mysql_error());
}
js controller
app.controller('ideasController', function($scope, $http) {
getIdea(); // Load all available ideas
function getIdea(){
$http.get("ajax/getIdea.php").success(function(data){
$scope.ideas = data;
});
};
$scope.addIdea = function (idea) {
$http.get("ajax/addIdea.php?idea="+idea).success(function(data){
getIdea();
$scope.ideaInput = "";
});
};
?>
This is what used to work.
<div class="col-sm-3">
<button ng-click="addNewClicked=!addNewClicked;" class="btn btn-sm btn-danger header-elements-margin"><i class="glyphicon glyphicon-plus"></i> Add New Idea</button>
</div>
<div class="col-sm-3">
<input type="text" ng-model="filterIdea" class="form-control search header-elements-margin" placeholder="Filter Ideas">
</div>
</div></div>
<div class="widget-body ">
<form ng-init="addNewClicked=false; " ng-if="addNewClicked" id="newIdeaForm" class="add-idea">
<div class="form-actions">
<div class="input-group">
<input type="text" class="form-control" name="comment" ng-model="ideaInput" placeholder="Add New Idea" ng-focus="addNewClicked">
<div class="input-group-btn">
<button class="btn btn-default" type="submit" ng-click="addIdea(ideaInput)"><i class="glyphicon glyphicon-plus"></i> Add New Idea</button>
</div>
</div>
</div>
</form>
try to add your controller reference in the div:
<form>
<div ng-controller="ideasController">
<input type="text" class="form-control" name="idea" ng-model="ideaInput">
<button class="btn btn" ng-click="addIdea(ideaInput)">Add
New Idea</button>
</div>
</form>