Passing PHP variable to Modal Window in same page - php

I am stuck with modal window. My modal window is on same page which I put in <div>, this modal window will popup when user click on a 'Reply Message' text.
while (($i < $num3b)&&($i < ($start+$perpage))) {
$tododetail_id=mysql_result($result3b,$i,"tododetail_id");
$comment=formatUrlsInText(mysql_result($result3b,$i,"comment"));
$staff_name=mysql_result($result3b,$i,"staff_name");
echo "<tr><td><span><font color='#5858FA'>" . $staff_name . nl2br($comment) . "</font>
<span style='float:right' id='create-user'>Reply Message</span>";
$i++;}
And Modal Window will appear using below code, i want to pass $staff_name and $comment so that it will appear in modal window. but i don't know how to call and pass those variables
$(function() {
var repmsg = $( "#repmsg" );
$( "#dialog-form" ).dialog({
autoOpen: false,
height: 280,
width: 660,
modal: true
});
$( '[id^="create-user"]')
.click(function() {
$( "#dialog-form" ).dialog( "open" );
});
});
Here my modal window code
<div id="dialog-form">
<p class="validateTips"><!--show php variable ($staff_name)--></p>
<form>
<fieldset>
<textarea class="text ui-widget-content ui-corner-all" name='repmsg' cols='100' rows='8' tabindex='1004'></textarea><br/>
<span id="quote" style="float:left">Requote</span>
<span style='float:right' id='button'>
<span id="add" class="button_form" style="cursor:pointer;">Add</span>
<span id="cancel" class="button_form" style="cursor:pointer;">Cancel</span>
</span>
</fieldset>
</form>
</div>
Hopefully you can understand my statement. Thank you.

In your loop you create several span with the same id. An id must be unique in a html page.
You must create different ids. This will also allow you to get the data with jquery.
Also think about putting your staff name in a separate div or span. This will ease accessing it.

In below part, just put the staffname variable:
<p class="validateTips"><?php echo $staff_name; ?></p>
This staffname will be shown when dialog opened

Related

jQuery dialog will not post textarea value

I have followed a few other suggestions on this site but I cannot get the data from a textarea within a jQuery dialog element to post. The most relevant answer was provided in the ASP.NET button discussion here, I have added the suggestion to my code with no change in results.
Here is what I have:
$(function() {
$("#dialog").dialog({
autoOpen: false,
modal: true,
resizable: false,
dialogClass: "no-close",
buttons: {
"Done": function() {
$(this).dialog("close");
}
}
})
$( "#opener" ).click(function() {
$( "#dialog" ).dialog( "open" );
}).parent().appendTo("form1");
});
I have tried adding the ".appendTo()" syntax to both the .dialog and function with no change. Any help would be greatly appreciated.
Here is the html for reference as well
<div id="dialog" title="Enter Comments">
<textarea id="feedback" name="feedback" rows="5" autocomplete="off" value="<?php get_data("feedback"); ?>" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> ></textarea>
</div>
<input type="button" class="btn btn-primary btn-block" value="enter comments" id="opener" <?php if (isset($disable) && $disable === true) echo ' disabled="disabled"'; ?> />
Thanks for all of the feedback! I have this figured out.
I ended up mirroring the data from the textarea to a text input within the form, I wrapped the input in a hidden div to keep it out of sight.
HTML
<div id="feedbackvalue">
<input type="text" name="sc_comment" id="sc_comment" value="<?php echo $sc_comment; ?>" />
</div>
CSS
#feedbackvalue {
display: none;
}

how to show/hide divs when divs are created dynamically

I am developing comment systems with two level of replay to the comments and I have a problem with how to show and hide divs .., because it's id's are different .., I tried in a way with:
<button>replayl</button>
<span style="display:none;">
<form action='' method='post' name="addcmt" onsubmit="return validate()">
<textarea rows="1" cols="60" name='textarea1' id='textarea1' onKeyDown="limitText(this.form.textarea1,this.form.countdown,300);"
onKeyUp="limitText(this.form.textarea1,this.form.countdown,300);">
</textarea>
<br>
<br>
<input type="hidden" name="level1" id="level1" value="commtlevel1" />
<input id='addcmt' type='submit' value='Add reply' name='submit'/>
</form>
</span>
and jquery:
<script>
$("button").click(function () {
$("span").show();
});
</script>
but this way when I click reply button it shows all the span tag contente.., I wanna kow how I show one tag only or a way to my work done.
As there is no button in your HTML, it's partly a guess. But the following code will toggle the visibility of the span immediately following your button :
$(document.body).on("click", "button", function () {
$(this).next("span").toggle();
});
Note that you'd better define some classes to make the selector more selective :
$(document.body).on("click", "button.toggler", function () {
$(this).next("span").toggle();
});
After edited question, i suggest you use div instead of span (because of display inline vs block).
$("button").click(function () {
$(".myform").toggle('slow');
});
would do the job how you want.Here is the result.

launching a jquery pop up window on html form submit?

can anyone please help. i have this login form:
<form id="myform" form action="login.php" method="post" class="loginform">
Email
<input type="text" name="email" maxlength="30" />
Password
<input type="password" name="password" maxlength="30" />
<input type="image" src="../PTB1/assets/img/icons/loginarrow1.png" name="submit" class="loginbutton" value="Login" />
</form>
i also have this script which brings up the form action page "login.php" in a popup window when my form is submitted.
at the moment it brings up a basic pop up window but i want to know if i can tweak the jquery code to implement a jquery lightbox window which opens up instead.
heres the jquery code that launches the pop up window when my login form is submitted.
<script>
$(document).ready(function() {
$('#myform').submit(function() {
window.open('', 'formpopup', 'width=400,height=400');
this.target = 'formpopup';
});
});
</script>
but now i want to have this pop up window open using my jquery lightbox window which is called "shadowbox" (available to download on the net) which you would normally open your links with like so.
<a href="link" rel="shadowbox;height=300;width=500" >link</a>
so just to be clear, i am asking if there is a way to launch my jquery lightbox "shadowbox" in place of the normal pop up window which is being launched when the user clicks the submit button on the login form.
Please can someone show me a way of doing this. thank you.
I would add e.preventDefault() to the previous statement
$(function() {
$('#myform').submit(function(e) {
e.preventDefault();
this.target = 'formpopup';
Shadowbox.open({
content: 'link',
height: 300,
width: 500
});
});
});
$(function() {
$('#myform').submit(function() {
this.target = 'formpopup';
Shadowbox.open({
content: 'link',
height: 300,
width: 500
});
});
});

Jquery dialog box error

I am using a dialog box to display and submit a enquiry form on my page.I am having problem when I try to call it again and again.The first time everything works fine and the form s submitted successfully.But if I click the GO button(added html below).I get an error for this line document.
EDITED:
<div class="hidden" id="dialog">
<form action="index.php" class="testForm" id="testForm">
<div class="name" id="name">
<div class="displayName" id="dispName">Name</div>
<div class="textName" id="viewName"><input type="text" class="fname" id="fullName" /></div>
<div class="hide" id="nameErr"></div>
</div>
<div class="address" id="addressDetails">
<div class="displayAddress" id="dispAddress">Address</div>
<div class="textAddress" id=""><input type="text" class="taddress" id="fullAddress" /></div>
<div class="hide" id="addressErr"></div>
</div>
<div class="submitForm" ><input type="button" class="submitDetails" id="submitInfo" name="Submit" value="Submit" onClick="validateAndSubmitForm()"/>
<a name="Close" onclick="$('#dialog').dialog('close');">Close</a>
</div>
</form>
</div>
Javascript\jquery
function submitEnquiryForProperty()
{
document.forms.testForm.reset();
$("#dialog").dialog({
modal:true,
resizable:false,
autoOpen:false,
width:260,
});
openDialog();
}
function openDialog(){
$("#dialog").dialog("open");
}
function closeDialog(){
$("#dialog").dialog("close");
}
Callback function on form submit
$.ajax({
type:'POST',
url:"processForm.php",
data:"name="+name+"&address="+address,
dataType:"html",
success:function(msg){
if(msg=="success"){
$("#dialog", window.parent.document).html("<div class='pad5'><div class='flt' style='padding-left:3px; width:235px;'><div class='thanx_msg'>Thank you for submitting the details. <br /><div class='spacer5'> </div><span class='gre'>Our Sales team shall revert to your query soon.</span></div></div><div class='spacer5'> </div><div style='padding-left:3px;' class='text'><strong>You can also:</strong></div><div style='margin-left:20px; line-height:20px;'>• Apply for a <a href='homeloan.php'>Home Loan</a><br />• Visit <a href='http://www.proptiger.com'>proptiger.com</a> for more properties<br />• See our <a href='http://www.proptiger.com/blog'>Blog</a> for latest updates</div></div><br/><div class='msg' style='color:red;'>Click to close the box</div>");
$(function(){
$('#dialog').click(function() {
closeDialog();
});
});
}
else
{
alert("Operation cannot be completed,please try again");
}
}
But I am facing the same problem.Error at the .reset() line.
Thanks for your time.
Updated answer
If you want to have a reusable dialog, do it like this:
Include the dialog element (almost assuredly a <div>) in your initial HTML. Use a CSS class so that it will not be immediately visible, for example:
HTML:
<div id="dialog" class="hidden">...</div>
CSS:
.hidden { display: none }
Unconditionally call $("#dialog").dialog(options) from Javascript immediately after the page loads. Be sure to set autoOpen: false in the options.
Whenever you want to display the dialog, use $("#dialog").dialog("open").
Whenever you want to hide the dialog, use $("#dialog").dialog("close").
Repeat steps 3 and 4 as much as you like.
.dialog( "destroy" )
Remove the dialog functionality completely. This will return the element back to its pre-init state.
.dialog( "close" )
Close the dialog.

Finding id of elements

i have this bit of html.
(Link at bottom)
Its output of php code for status updates, it has view comments and post comment link, the post comment link uses jquery to add a textarea and submit button below that status update. and the view comments shows the comments to that status update below that status update.
So i use php looping so there will be obviously more than 1 status updates at most times(depends on how much friends users have) so i cant have an element like 'textelement', i will need to have elements like 'textelement1' and 'textelement2'
So i used php to add the id of the status update in the end of the links like _id so the element id becomes view_comments_1.
So i want to use jquery to find out which element has been clicked so that i can add a text box and show comments below the right status update instead of showing it below all status updates.
HTML
<div class="wrapbg">
<span class="corners-top"><span></span></span>
<div id="content"><br/>
Whats new?
<hr class='hr1'>
<div class='stbody' id='stbody'>
<div class='stimg'>
<img src='uploads/profile_pics_small/Anonymous_Blueprint_Wallpaper_by_co.jpg' /></img>
</div>
<div class='sttext'>
Welcome yoall!!
<div class='sttime'>By LUcase</div>
<br><br>
<a href=''>0 Likes</a> <a href=''>1 Dislikes</a>
</div>
<a href=''>unDislike</a> <a id='comment_now_1' href=''>Comment</a> <a id='view_comments1' data-id-1 = '1' href=''>View comments</a> <div id='emptydiv1'> </div></div>
<div class='stbody' id='stbody'>
<div class='stimg'>
<img src='uploads/profile_pics_small/wood_texture_by_pabloalvin-d1igijr.jpg' /></img>
</div>
<div class='sttext'>
hi
<div class='sttime'>By nicknick</div>
<br><br>
<a href=''>0 Likes</a> <a href=''>0 Dislikes</a>
</div>
<a href=''>Like</a> <a href=''>DisLike</a> <a id='comment_now_4' href=''>Comment</a> <a id='view_comments4' data-id-4 = '4' href=''>View comments</a> <div id='emptydiv4'> </div></div></div>
<span class="corners-bottom"><span></span></span>
</div>
JavaScript
//Gotta find out which status update we are dealing with!
jQuery("document").ready(function(){
jQuery(".likebtn").click(function(e) {
var id=jQuery(this).attr("data-id");
jQuery.post('like.php', {'id': id}, function(data) {
alert("Your like.php has been called");
}, "json");
e.preventDefault();
});
jQuery(".dislikebtn").click(function(e) {
});
//gotta figure out which status update we are dealing with!
//attache the click event to the anchor tag
$("#comment_now").live("click",function(e){
//prevent the default behaviour of following the link
e.preventDefault();
$("#comment_now").remove();
//find the textarea element, and after it, put an input tag
$(".sttext").after('<textarea id="comment_text" name="comment"></textarea> <br> <button id = "post_button" class="action greenbtn"><span class="label">Comment</span></button> <a id="cancel_comment" href="">Cancel</a> <br id="com_spacing">');
});
//gotta figure out which status update we are dealing with!
$("#cancel_comment").live("click",function(event){
event.preventDefault();
$("#comment_text").remove();
$("#cancel_comment").remove();
$("#post_button").remove();
$("#com_spacing").remove();
$("#view_comments").before('Comment ');
});
$("#view_comments").live("click", function(e){
e.preventDefault();
var id=jQuery(this).attr("data-id");
$.ajax({
url: 'query_comments.php?status_id='+id,
beforeSend: function( xhr ) {
xhr.overrideMimeType( 'text/plain; charset=UTF-8' );
},
success: function( data ) {
$('#emptydiv').html(data);
}
});
});
});
Please help me out :)
You know that html forms can send arrays, right?
<input type="text" name="textelement[]" value="First Element" /><br/>
<input type="text" name="textelement[]" value="Second Element" /><br/>
PHP Code:
foreach($_POST['textelement'] as $somethingSomething){
echo $somethingSomething, "\n";
}
Prints out:
First Element
Second Element
add a class to to action buttons and pass the comment id as data attribute like so:
<a class="commentBtn" href='' data-commentid="1">Comment</a>
and than you can read out the id easily with jquery:
$(".commentBtn").live("click",function(e){
var id = $(this).data('commentid');
e.preventDefault();
// do something with id…
});

Categories