开发者

guidance question for a major code .... how could i make every list inserted by users clickable ?

ok so, im nothing of an expert, so i need guidance on how to go about this:

I got a php document, where theres is a form. Everytime a user submits text on the input, the text echos as a li inside an ul thats on a div. It does that by calling a function on the document load, it uses php and jquery. heres the code:

<script type="text/javascript">


$(document).ready(function(){
    $("form#postbar_add_post").submit(function() {
        var addcontentbox = jQuery('#addcontentbox').attr('value');

        if ( addcontentbox.replace(/\s/g,"") == "" ) return false;

$.ajax({
type: "POST",
url: "postear.php",
data:"addcontentbox="+ addcontentbox,
success: function(){
$("ul#wall").开发者_Python百科prepend("<li>"+addcontentbox+"</li>");
$("ul#wall li:first").fadeIn();
document.postbar_add_post.addcontentbox.value='';
document.postbar_add_post.addcontentbox.focus();
}
});
return false; 
});
});
</script> 

On the code above, postbar_add_post is the name of the form, addcontentbox is the input field and then "wall" is the id of the unsorted list. As you see, the url is a php, called postear. heres that php:

<?php
if( isset($_POST['addcontentbox']))
   {
   // Connection to Database
   include('config.php');

   // Preventing Query Injection
   $message = mysql_real_escape_string($_POST['addcontentbox']);

   // the echo
   $sql = 'INSERT INTO WALL (message) VALUES( "'.$message.'")';
   mysql_query($sql);

   echo $message;
   }
else
   { 
   echo '0';
   }
?> 

everythign works fine, only that, im thinking now that I want to make every list that is inserted by the user to direct to a new page with that li as a h1 when is clicked.

only that i have no idea how to go about that.. so far, every list inserted is not even clickable.. and i dont know much about mysql/php...

What i seek here is maybe a guidance on how can that be done.. ( IFF can b done)..

I guess it would be something like, changing the php so it would add an id to every list that is inserted... but my brain is not that smart.

Can any body guide me here? where to go? what to think? how to?


you can do something like this,

 $("ul#wall li").click(function(){
     location.href='your url'//

  });

or else, you can add a hyperlink in your li like this,

//...
$("ul#wall").prepend("<li><a href='Your URL'>"+addcontentbox+"</a></li>");
$("ul#wall li:first").fadeIn();
//..
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜