0

Dear Friendzz,

Problem to getting dynamic values in Javascript.. Please Helpme

// Java Script

<script language="javascript">
function toggle(int) {
	var ele = document.getElementById(int);
	if(ele.style.display == "block") {
    		ele.style.display = "block";
  	}
	else {
		ele.style.display = "block";
		text.innerHTML = "hide";
	}
} 
</script>

// HTML

<div class="reply">
<a id="{$msg['id']}" href="javascript:toggle(this);">Reply</a>
</div>

Thanks Inadvance

Edited by Ezzaral: Added code tags. Please use them to format any code that you post.

3
Contributors
6
Replies
13
Views
6 Years
Discussion Span
Last Post by ko ko
0

toggle(this)

this IS the <a> tag so you do NOT need:
var ele = document.getElementById(int);

all you need is:

<script language="javascript">
//function toggle(int) {
//var ele = document.getElementById(int);
function toggle(ele){
  if(ele.style.display == "block") {
  ele.style.display = "inline";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
}
} 
</script>
0

Hey Hielo,

That is not working dude.. kindly please help me

0

That is not working dude

You need to be more descriptive. Imagine calling your doctor and saying "I am not feeling well. Please write me a prescription"

The only thing that stands out from your original post is: text.innerHTML = "hide"; I don't see where you defined "text". Did you perhaps mean ele.innerHTML="hide";

0

Maybe, your need is this one.

<script language="javascript">
function toggle(ele){
  var msgbox = document.getElementByID(ele.id);
  if(msgbox.style.display == "block") {
  msgbox.style.display = "none";
  ele.innerHTML = "Reply";
}
else {
msgbox.style.display = "block";
ele.innerHTML = "Hide";
}
} 
</script>

Hope this help.

0

Hey Dude,
Am Developing A Social Networking Website.. When user posted a message return user have to reply to that message. but we have somany reply boxes calling with the above id. if the dynamic id works my problem is over...

HTML CODE:


echo "<div class='pingreply'>";
echo "<a id='{$msg}' href='javascript:toggle(this);'>Reply</a>";
echo "</div>";

*****************
If user click the above link the below reply box should be open for replying him..
*****************

echo "<div id='{$msg}' style='float: left; height: 36px; margin: 10px; padding-top: 10px; width: 80%; display: none;'>";
echo "<form action='' method='post'><input type='text' value='Ping back' class='pingreply' name='pingrply'></form>";
echo "</div>";

JAVA SCRIPT:

// Java Script

<script language="javascript">
function toggle(int) {
var ele = document.getElementById(int);
if(ele.style.display == "block") {
ele.style.display = "block";
}
else {
ele.style.display = "block";
text.innerHTML = "hide";
}
}
</script>

*******************
If user click on reply link.. the associated textbox should open to reply the associated id.. that is my problem.. thanks in advance...
*******************

Edited by rayidi: missing explanation

0

Use jquery more simple and clear. You should separate the reply form in another php file. When the user click the reply button, call ajax function to the file where the reply HTML form located. Here is my example:

$(document).ready(function(){
    $('.reply').click(function(){
         $.ajax({
                 type: "GET",
                 url: "reply.php",
                 data: "reply_id="+$(this).attr('id'),
                 success: function(data){
                           $(this).next().append(data);
                          }
               })
    })
})

@reply.php
<?php
$reply_id = $GET['reply_id'];
?>
<form name="replyform" method="post" action="replymessage.php">
<input type="text" name="reply<?php echo $reply_id; ?>" id="reply<?php echo $reply_id; ?>" />
<input type="submit" value="Reply" name="reply" id="reply" />
</form>

And attach the class to the handler element, the reply link.

<a id="{$msg['id']}}" class="reply" href="javascript:;">Reply</a>

With my example, you need only one form for reply. With your version, the server is generating the reply form followed by every reply links, and the server will also be generated the comment forms while the new comment have been created. It makes the file size larger and too much unnecessary HTML will be output. Hope that help.

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.