product.php
function getdata(getdatafrom, resultclass){
$.get(getdatafrom, function(data) {
$(resultclass).html(data);
});
}
getdata('get.php?action=porsiyondurum2&id=<?php echo $urunid; ?>','#porsiyondurum2');
get.php
$action = htmlspecialchars(mysql_real_escape_string($_GET['action']));
if($action=="porsiyondurum2"){
$id = htmlspecialchars(mysql_real_escape_string($_GET['id']));
$urunporkont = mysql_query("SELECT * FROM porsiyon WHERE urunid='$id'");
$urunporkonts = mysql_num_rows($urunporkont);
while($urunporkontv = mysql_fetch_array($urunporkont)){
$porid = $urunporkontv['id'];
$porname = $urunporkontv['name'];
$porucret = $urunporkontv['ucret'];
echo '<tr><form action="post.php?action=porguncelle&id='.$porid.'" method="POST" target="frame'.$porid.'"><td><input name="porname" type="text" class="form-control" placeholder="'.$porname.'" value="'.$porname.'"></td><td><div class="input-group">
<input type="number" name="porucret" class="form-control" min="0" placeholder="'.$porucret.'" value="'.$porucret.'">
<span class="input-group-addon">₺</span>
</div></td><td class="text-center"><iframe name="frame'.$porid.'" src="not_submitted_yet.php" ></iframe><button class="btn btn-primary btn-sm" onClick="test()" type="submit"><i class="fa fa-edit"></i> Güncelle</button> <button class="btn btn-danger btn-sm" ><i class="fa fa-trash"></i> Sil</button></td></form></tr>';
}
echo '<tr><td><input type="text" class="form-control" placeholder="Porsiyon Adı"></td><td><div class="input-group">
<input type="number" class="form-control" min="0" placeholder="Ücret">
<span class="input-group-addon">₺</span>
</div></td><td class="text-center"><button class="btn btn-primary btn-sm"><i class="fa fa-plus"></i> Yeni Ekle</button></td></tr>';
}
As you can see. I can see get.php codes at product.php. But when I trying to frame post it. It doesnt work. Or I tried ajaxpost it didnt happened also. But when I copy this code to product.php It posts perfectly. How can I do this?
Edited: Guys its not php problem. I just wrote related part on get.php
$action is not defined (per the code you've provided), so your initial condition that the entire get.php script relies on, fails.
if($action=="porsiyondurum2"){
Because it's being passed in a GET querystring, you need to handle it in that manner, like your other values being passed:
if($_GET['action'] == "porsiyondurum2"){
See how you got the id by doing just that: $_GET['id']. Same applies for action.
In Addition
I don't see where you're connecting to your database in get.php, either. Is there more to the script than what you've posted here? If so, please add it to your post and I will remove this answer (unless it resolves your problem).
Related
I'm sorry if there's already a question like this, but I've found nothing about this, nor do I know exactly what to look for.
The problem:
When I copy #download_link via the copy button it only copies 53297234.png instead of 5ec8515390d267.53297234.png
My code:
<script>
function copy2clip(element) {
var $temp = $("<input>");
$("body").append($temp);
$temp.val($(element).text()).select();
document.execCommand("copy");
$temp.remove();
}
</script>
<div class="input-group mb-3">
<div class="input-group-prepend">
<button class="btn btn-outline-secondary" type="button" onclick="copy2clip('#download_link')">Copy</button>
</div>
<input type="text" class="form-control" id="download_link" placeholder="Link" value="https://example.org/u/". $row['name'] ."" disabled>
</div>
$row['name'] = 5ec8515390d267.53297234.png
Thanks in advance :)
I'm not sure why you're getting a partial string--the code shouldn't work as is. Assuming your PHP variable concatenation is working (it's a good idea to establish that, then remove it from the question so it's reproducible and isolated), the .text() function can't be used to access an input element's value. Use $(element).val() instead.
From the docs:
The .text() method cannot be used on form inputs or scripts. To set or get the text value of input or textarea elements, use the .val() method.
As an aside, I wouldn't use $ to prefix your vars in JS. It's not a typical style and makes it confusing to see what's jQuery and what's JS.
If this doesn't solve the problem, then the issue is likely in your PHP script. Make sure it's concatenating correctly.
function copy2clip(element) {
var temp = $("<input>");
$("body").append(temp);
temp.val($(element).val()).select();
document.execCommand("copy");
temp.remove();
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<div class="input-group mb-3">
<div class="input-group-prepend">
<button
class="btn btn-outline-secondary"
type="button"
onclick="copy2clip('#download_link')"
>Copy</button>
</div>
<input
type="text"
class="form-control"
id="download_link"
placeholder="Link"
value="https://example.org/u/5ec8515390d267.53297234.png"
disabled
>
</div>
If you are interested in writing some fancy clean code, you should check this library
clipboard.js .
Example:
// you need to instantiate it by passing selector
new ClipboardJS('.btn');
<!-- Include the script via CDN (you can download it) -->
<script src="https://cdnjs.cloudflare.com/ajax/libs/clipboard.js/2.0.4/clipboard.min.js"></script>
<div class="input-group mb-3">
<div class="input-group-prepend">
<!-- Trigger -->
<button class="btn btn-outline-secondary" type="button" data-clipboard-target="#download_link">Copy</button>
</div>
<input type="text" class="form-control" id="download_link" placeholder="Link" value="https://example.org/u/" .
$row['name'] ."" readonly>
</div>
In my project, while a particular button is clicked I want to stop the next page appearing. Here is my JavaScript code:
function checkcond() {
check_value=document.getElementById("chkvalue");
if(check_value==null){
alert(check_value);
document.firstform.textview.focus();
return false;
}
}
and button code is:
<form id="payment_form" name="payment_form" action="<?php echo site_url("cont/accept");?>" method="post">
<input id="chkvalue" name="chkvalue" type="hidden">
<button type="submit" id="submit_button" class="btn btn-primary" onclick="checkcond()">
<b>Make a Payment</b>
<span class="fa fa-hand-o-right" aria-hidden="true"></span>
</button>
Here after checking the check_value I want to keep my current page while it is null. How should it be done? Is there any function for that?
My suggestion would be to remove inline javascript
and use like this
document.getElementById('payment_form').onsubmit = function() {
return checkcond();
};
or if you want to use inline method, change onclick method like this
<button type="submit" id="submit_button" class="btn btn-primary" onclick="return checkcond()"><b>Make a Payment</b>
I have on my delete function a message for confirmation of delete when i put ok nothing is done
Function from controller
public function destroy($id)
{
$client =client::find($id);
$client->delete();
return redirect('client');
}
view client
<form action="{{url ('client/'.$client->id)}}" method="post">
{{csrf_field()}}
{{method_field('DELETE')}}
<a href="{{url('client/'.$client->id.'/show')}}"
class="btn btn-default btn-sm">Details</a>
<a href="{{url('client/'.$client->id.'/edit')}}"
class="btn btn-primary btn-sm">Editer</a>
<a class="btn btn-danger btn-sm" title="Delete"
href="javascript:if(confirm('Are you sure want to
delete?')) $('#frm_{{$client->id}}').submit()">
Supprimer
</a>
</form>
in your route file just change like this
Route::get('/client/{id}/delete', 'ClientController#destroy');
in your view
Delete
$('#frm_{{$client->id}}').submit() is a jQuery code, are you sure your page have jQuery properly loaded?
Better use plain javascript: document.getElementById("myForm").submit()
i think you forget to add id attribute for you form
<form action="{{url ('client/'.$client->id)}}" id="frm_{{$client->id}}" method="DELETE">
This can be done easily by:
<a onclick="if(confirm('Are you sure you want to delete this item?')){ deleteFunction() };">Delete</a>
I've been trying to push through a PHP variable $getUserID to a JavaScript function that doesn't seem to accept it. I've been looking through a lot of answers on stackoverflow as well as the internet in general but I haven't found a solution yet.
Code:
PHP :
<!-- Comments Form -->
<div class="well">
<h4>Leave a Comment:</h4>
<form role="form" method="post">
<div class="form-group">
<textarea class="form-control" rows="3" id="commentInput"></textarea>
</div>
<button type="submit" onclick="checkComment(<?php echo $getUserID ?>)" class="btn btn-primary">Submit</button>
</form>
</div>
JavaScript :
var comment = {
commentText: "",
userID: ""
};
function setValues() {
comment.commentText = document.getElementById("commentInput").value;
}
function validateComment(commentText) {
if(!(commentText === "" || commentText.length < 1))
return true;
}
function checkComment(userID) {
setValues();
alert(validateComment(comment.commentText));
comment.userID = userID;
alert(comment.userID);
alert(comment.commentText);
}
What I'm trying to do, for testing purposes, is to print alert messages to see if every variable is received. No alert messages pop up when I hit the submit button. I believe it is an error due to the php variable. Is anyone able to spot the error?
<button type="submit" onclick="checkComment(<?php echo $getUserID ?>)" class="btn btn-primary">Submit</button>
I wasn't using single quotations after "checkComment(".
Fixed code:
<button type="submit" onclick="checkComment(<?php echo $getUserID ?>')" class="btn btn-primary">Submit</button>
I have comment widget , i am loading all comments with like and dislike button . once user like any comment i want to hide like button and show dislike button .
is it valid ??
ng-show="likeClicked[{{comment.id}}]
As i am trying to use like this in my code and it is not working.
HTML
<div class="panel-body">
Comment ::{{comment.commentline}} <br/>
ID :: {{comment.id}}
Likes :: {{comment.like}}
<button type="button" class="btn btn-default btn-xs" ng-click="incrlikes(comment)" ng-hide="likeClicked[{{comment.id}}]">
<span class="glyphicon glyphicon-star"></span> Like
</button>
<button type="button" class="btn btn-default btn-xs" ng-click="decrlikes(comment)" ng-show="likeClicked[{{comment.id}}]">
<span class="glyphicon glyphicon-star"></span> DisLike
</button><br/>
Script ::
$scope.incrlikes=function(a)
{
var selectedIndex=$scope.comments.indexOf( a );
if(!$scope.likeClicked[$scope.comments[selectedIndex].id])
{
console.log('Likes increment for ::'+ $scope.comments[selectedIndex].name);
console.log( $scope.comments[selectedIndex].id +'with index of name is '+$scope.comments[selectedIndex].name );
// $scope.comments.indexOf(selectedIndex).like=$scope.comments.indexOf(selectedIndex).like+1;
$scope.comments[selectedIndex].like=$scope.comments[selectedIndex].like+1;
$scope.likeClicked[$scope.comments[selectedIndex].id]=true;
}
else
{
console.log('Already like' + $scope.likeClicked[$scope.comments[selectedIndex].id]);
}
};
For above code ng-hide,ng-show button is not working ??
I think what you need is
ng-show="likeClicked[comment.id]"