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

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>

Hey Hielo,

That is not working dude.. kindly please help me

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";

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.

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...
*******************

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.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.