2

How do I get this form input to be stored in a variable, that I can then use later - rather than being appended to the end of the URL?

    <script type="text/javascript">

        $(function() {
                var tag_box = $("<div>").appendTo("body").css({
                    "width": "40px",
                    "height":"40px",
                    "border":"4px solid #000000",
                    "position":"absolute",
                    "display":"none", 
                    "padding":"15px"
                    });

            var comment_box = $("<form action='#'><input id='comment' type='text' name='comment' placeholder='Add comment'></form>").appendTo(tag_box).css({"position":"absolute"});


            $("#image-wrapper").live("click", function(e) {
                tag_box.css({
                    "left": e.pageX - 40,
                    "top": e.pageY - 40, 
                    "display": "block"
                    })
                .after(comment_box.css({
                    "left": e.pageX - 65,
                    "top": e.pageY + 40
                }));
                 return false;  
                });

            });

</script>
<body>

<div align="center">  

    <img src="images/ror1.gif" width="760" height="182" alt="Ror1" id="image-wrapper">

</div> 
</body>
marcamillion
  • 32,933
  • 55
  • 189
  • 380

1 Answers1

1

Prevent it from submitting by returning false from the submit (onsubmit) event handler. The form data (param names + values) can be captured via serialize:

$("form").live("submit", function() {
    var params = $(this).serialize();
    alert(params);
    return false;
});
karim79
  • 339,989
  • 67
  • 413
  • 406
  • Karim...is there a way then to reset the form upon submission, so I can go ahead and continue collecting inputs - from the same user (preferrably without a page re-load). – marcamillion May 02 '10 at 01:18
  • 1
    @marcamillion - see here: http://stackoverflow.com/questions/680241/reset-form-with-jquery – karim79 May 02 '10 at 01:20