Setting a form value from QueryUI draggable - php

I'm trying to set a form value when mulitple draggable objects are dropped onto a form. Once all the draggables have been dropped, I want to press the submit for a PHP code to do some processing with the form values.
I just can't get the drop event to set the form value????
Here's the JqueryUI stuff..
$(function() {
$( ".player" ).draggable({ revert: "invalid" });
$( ".position" ).droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
accept:".player",
drop: function( event, ui ) {
var playerid = ui.draggable.attr("id");
var target = $(this).attr("id");
alert(playerid); //this works - got the right draggable id
alert(target); //this works - got the right droppable id
//!!!! THIS DOESN'T SET IT!!!!!
$('#resultform').attr('#target','playerid');
}
});
});
Here is the HTML
<div id="result_space">
<div id="player_list" class="player_list">
<p>This is the player space </p>
<div id="pos_1" class="player">
<p>Player 1</p>
</div>
<div id="pos_2" class="player">
<p>Player 2 </p>
</div>
</div>
<div id="pitch">
<form id="resultform" name="resultform" action="results_submit.php" method="post">
<table background="../_images/5_results/pitch_v2.jpg" width="560" border="1px">
<tr height="30"> <td colspan="4" align="center" style="color: #FFFF00; font-size: 24px;">stowupland falcons fc</td></tr>
<tr height="80" valign="bottom"><td colspan="4" align="center"><div class="position" id="goalie"> <input type="text" name="goalie" id="goalie" value="Player 1" /></div></td></tr>
<tr height="110" align="center" valign="middle">
<td width="25%"><div id="defence1"><input class="position" type="text" name="r_def_1" id="r_def_1" value="player 2" /></div></td>
<td width="25%"><div class="position" id="defence2"><input type="hidden" name="r_def_2" id="r_def_2" value="player 3" /></div></td>
</table>
<input name="submit" type="submit" id="submit" value="Submit" />
</form>
</div>
</div>
So as an example, I want to drag Player 1 (pos_1) to Defence 1 and make the form value r_def_1 = pos_1.

I made a few tweaks to get this to work:
I updated the HTML to make the tds droppable. This seems to work a little bit better. I also changed the colspan attribute of the tds appropriately.
Updated HTML:
<div id="result_space">
<div id="player_list" class="player_list">
<p>This is the player space </p>
<div id="pos_1" class="player">
<p>Player 1</p>
</div>
<div id="pos_2" class="player">
<p>Player 2 </p>
</div>
</div>
<div id="pitch">
<form id="resultform" name="resultform" action="results_submit.php" method="post">
<table background="../_images/5_results/pitch_v2.jpg" width="560" border="1px">
<tbody>
<tr height="30">
<td colspan="2" align="center" style="color: #FFFF00; font-size: 24px;" class="">stowupland falcons fc</td>
</tr>
<tr height="80" valign="bottom">
<td colspan="2" align="center" class="position">
<div class="" id="goalie">
<input type="hidden" name="goalie" id="goalie" value="Player 1" />
</div>
</td>
</tr>
<tr height="110" align="center" valign="middle">
<td class="position">
<div id="defence1">
<input class="" type="hidden" name="r_def_1" id="r_def_1" value="player 2" />
</div>
</td>
<td class="position">
<div class="" id="defence2">
<input type="hidden" name="r_def_2" id="r_def_2" value="player 3" />
</div>
</td>
</tr>
</tbody>
</table>
<input name="submit" type="submit" id="submit" value="Submit" />
</form>
</div>
</div>
JavaScript:
$(function() {
$(".player").draggable({
revert: "invalid"
});
$(".position").droppable({
activeClass: "ui-state-hover",
hoverClass: "ui-state-active",
accept: ".player",
drop: function(event, ui) {
var playerid = ui.draggable.attr("id");
$("input", this).val(playerid);
}
});
});​
The key is this line:
$("input", this).val(playerid);
which finds the input inside of the droppable td.
CSS (with draggable its useful to limit the width of draggable items):
​.player { width: 75px; }​
Example: http://jsfiddle.net/z8pWN/

Related

use span to hide and show content

i am new in both php and jquery. i want to use span to hide and show content in html and php. can i use jquery? if yes, what should i do? i already put the jquery script to the bottom of page. this is my code :
<!-- reply -->
<span title="fas fa-reply" name="reply" data-id="1"
</span>
<!-- if span clicked show all these data... -->
<table class="table table-borderless" style="margin-top:50px;">
<thead class="bg-secondary pb-0">
<tr>
<th colspan="3" class="pb-0">
<p class="test text-light">Creating Reply <?php echo $rowAllPost["id"]; ?>
</p></th>
<th class="pb-0 text-right">
</th>
</tr>
</thead>
<th scope="row" style="width:15rem!important;">
<img src="<?php echo $rowViewUserNow["picture"];?>" class="rounded-circle" style=height:93px;width:81px;><br>
<p class="ml-3"> Online</p>
<p class="ml-2"> <?php echo $rowViewUserNow["username"];?>
</p>
<i class="fas fa-info-circle pr-2 pt-2"></i>Active
<td colspan="3" class="text-justify">
<form action="controller/doCheckPost.php" method="post">
<textarea name="description" class="form-control"></textarea>
</td>
</tr>
<tr class="bg-secondary pb-0" >
<th colspan="3" class="pb-0">
<button title="Cancel" class="btn" type="submit" name="cancel"><i class="fas fa-times"></i></th></button>
<th class= "pb-0 text-right">
<button title="Submit" class="btn" name="submit"><i class="fas fa-check"></i></button>
</form>
</th>
</th>
</tr>
</div>
</tbody>
</table>
The best way would be to first give an id to both the span and table elements. Then you can use an event handler in jQuery like this:
$('#spanId').on('click', function() {
$('#tableId').toggle();
});
Toggle will show the element if it's hidden and hide it if it's visible.

Jquery not adding dynamic php

I have a basic form that submits the form data to the same page and do a simple search in a MySQL db. The php for this in before the <html> tag
<body>
<div data-role="page">
<div role="main" class="ui-content">
enter code here
<table style="width:750px;">
<form enctype="multipart/form-data" action="player_documents_m.php" method="get" data-ajax="false">
<tr style="height:35px;">
<td style="width:250px; vertical-align:top; text-align:left;">
<label for="name">Player Name: </label>
</td>
<td style="text-align:left; vertical-align:middle; text-align:center;">
<input type="text" name="name" id="name" class="inputs" size="45" value="<?php echo $my_name; ?>" maxlength="255"/>
</td>
</tr>
<tr style="height:35px;">
<td style="text-align:left; vertical-align:bottom; text-align:right;" colspan="2">
<input type="submit" name="search" id="search" value="Search Player" />
</td>
</tr>
</form>
</table>
The above works in JqueryMobile
Then the results are added dynamically with html content but this does not work in JqueryMobile but taking out all JQueryMobile related stuff and leave a normal php page everything works.
Below the table tag above I add my php to add the founded search results.
<?php
for($j = 0; $j < $i; $j++)
{
$photo = "images/" . $db_new . "/players/" . $player[$j]["player_id"] . ".jpeg";
echo "<br />";
?>
<!-- Search Results -->
<div class="singleResult" onclick="javascript: window.location.replace('load_documents.php?identification=<?php echo $player[$j]["player_id"]; ?>');">
<table border="1" style="width:100%; border: solid thin; padding:0; border-spacing:0;">
<tr>
<!-- Image 1st Column -->
<td rowspan="2" colspan="1" style="width:10%; vertical-align:top; text-align:left;">
<img src="<?php echo $photo; ?>" style="width:150px; height:180px;" />
</td>
<td class="labels">Name:
<p class="results"><?php echo $player[$j]["player_name"]; ?></p>
</td>
</tr>
</table>
</div>
<!-- End Of Search Results -->
<?php
}
?>
</div>
</div>
</body>
Now the above only works normally and not in JqueryMobile. can some please explain to me what I am doing wrong / need to add, or anything helpful please.
Thanks

Bind form entry to jquery script to .removeclass .addclass

I dynamically generated a php page with a single text element form and a table of data. Each row of the table has a barcode as the name (). As I scan each barcode in the form, I'd like to change the row color using jquery.
Php page simplified:
<form id="checkinProcess" class="mainForm" method="post" action="">
<label>Barcode:</label>
<input type="text" class="required" name="barocde" id="processBarcode"/>
<input type="submit" value="submit" class="blueBtn" />
</form>
<table class="display" id="barcodeTable">
<thead>
<tr>
<th>Barcode</th>
<th>Amount</th>
<th>Code</th>
</tr>
</thead>
<tbody>
<tr id="B12345" class="odd">
<td>B12345</td>
<td>20.3</td>
<td>External</td>
</tr>
<tr id="B23456" class="even">
<td>B23456</td>
<td>19.6</td>
<td>Internal</td>
</tr>
<tr id="B34567" class="odd">
<td>B34567</td>
<td>22.0</td>
<td>Internal</td>
</tr>
</tbody>
</table>
Table Css:
tr.odd { background-color: #F9F9F9; }
tr.even { background-color: white; }
tr.curChecked {background-color: #33CC33; }
jQuery attempt:
$('#checkinProcess').submit(function(e){
e.preventDefault();
$("tr.processBarcode").removeClass("odd" "even").addClass("curChecked");
});
How do I pass the barcode scanned in the form to my JQuery to identify which tr tag's class I want changed? Can I even do that?
Thanks
<script>tr.curChecked {background-color: #33CC33; } </script>
<form id="checkinProcess" class="mainForm" method="post" action="">
<label>Barcode:</label>
<input type="text" class="required" name="barocode" id="processBarcodes" />
<input type="submit" value="submit" class="blueBtn" id="submitBtn" />
</form>
<div class="table">
<table class="display" id="testTable">
<thead class="tableheader">
<tr><th>No</th><th>Name</th><th>Age</th><th>Salary</th></tr>
</thead>
<tbody id="testBody">
<tr id="B000506" ><td>1</td><td>Abe</td><td>28</td><td>$100K</td></tr>
<tr id="B000501" ><td>2</td><td>Jimmy</td><td>29</td><td>$90K</td></tr>
<tr id="B000506" ><td>3</td><td>Dude</td><td>18</td><td>$50K</td></tr>
<tr id="B000506" ><td>4</td><td>Boyee</td><td>28</td><td>$40K</td></tr>
</tbody>
</table>
<script>
$(document).ready(function() {
$("#submitBtn").on("click", highlight);
function highlight(evt) {
evt.preventDefault();
var scanbc = $("#processBarcodes").val();
$("#" + scanbc).addClass("curChecked");
$("#processBarcodes").val('');
$("#processBarcodes").focus();
</script>
Worked.

fancybox gallery with voting

I have a fancybox gallery that is working perfectly but when I do a submit for voting instead of processing the form it goes to the next image
The fancybox script
$(".fancybox-button").fancybox({
prevEffect : 'fade',
nextEffect : 'fade',
closeBtn : false,
helpers : {
title : { type : 'inside' },
buttons : {}
}
});
The HTML page
<div class="showContestant"><a class="fancybox-button" rel="fancybox-button" href="viewDetail.php?id=1" title="Fine Gal One">
<img src="images/pix1.jpg" width="100" /></a></div>
<div class="showContestant"><a class="fancybox-button" rel="fancybox-button" href="viewDetail.php?id=4" title="Fine Gal two">
<img src="images/pix4.jpg" width="100" /></a></div>
<div class="showContestant"><a class="fancybox-button" rel="fancybox-button" href="viewDetail.php?id=2" title="Fine asdfasfasf asfasfasfsadf Gal three">
<img src="images/pix2.jpg" width="100" /></a></div>
The PHP page called
<? if (isset($_REQUEST['cid'])) { echo 'posted';} else{?>
<form id="form1" name="form1" method="post" action="">
<table width="500" border="0" align="center" cellpadding="0" cellspacing="0">
<tr>
<td align="center"><img src="images/pix<?=$_REQUEST['id'];?>.jpg" width="400" height="400" /><input name="cid" id="cid" type="hidden" value="<?=$_REQUEST['id'];?>" /></td>
</tr>
<tr>
<td>My Picture Description: i am looking great in my red top!!!<br />
Vote this Contestant;</td>
</tr>
<tr>
<td><input type="submit" name="Vote" id="Vote" value="Vote Me!!!" /></td>
</tr>
</table>
</form>
<? } ?>
Add this API options
arrows: false,
closeClick: false,
.

ReCaptcha doesn't show up on Facebox

<?php
session_start();
require_once('recaptcha/recaptchalib.php');
$publickey = "API_KEY"; // you got this from the signup page
?>
<script type="text/javascript" src="javascripts/jquery.form.js"></
script>
<script type="text/javascript">
$(document).ready(function() {
$('#inquiry').ajaxForm({
target: '#error',
success: function() {
$('#error').fadeIn('slow');
}
});
});
var RecaptchaOptions = {
theme : 'clean'
};
</script>
<div class="top_area">Inquiry Form</div>
<div id="search_area">
</div>
<div style="overflow-y: hidden;">
<form name="inquiry" id="inquiry" action="asadadasd.php"
method="post">
<div id="error"></div>
<table align="center">
<tr>
<td valign="top" align="right"></td>
<td>
<?php
echo recaptcha_get_html($publickey);
?>
</td>
</tr>
<tr>
<td valign="top"></td>
<td>
<input type="submit" id="submit" name="submit" value="Submit"
style="height: 30px; background: #ab2220; border: 2px #fff solid;
color: #fff;" />
</td>
</tr>
</table>
</form>
</table>
</form>
</div>
That's the code I have as of now but recaptcha plugin doesn't show up
am I missing something?
Thanks guys,
You are so awesome
You have to use the recaptcha AJAX API on facebox. Include the AJAX script in your page (Not the page facebox will display. Put it in the containing page) Then use the recaptcha api as specified in the docs.
http://code.google.com/apis/recaptcha/docs/display.html#AJAX

Categories