tags:

views:

32

answers:

3

This JS is giving me some problems. Specifically FF3.5 is saying there is Error: missing ; before statement and its pointing at the 'comsn=' + comsn section. I know enough js to get myself into trouble, but specifics, im not there yet. Any ideas?

<script type="text/javascript" >
$(function () {
    $(".submit").click(function () {
     var comsn = $("#comsn").val();
     var comrn = $("#comrn").val();
     var compic = $("#compic").val();
     var comment = $("#comment").val();
     var eventid = $("#eventid").val();
     var comuserid = $("#comuserid").val();
     var owner = $("#ownerid").val();
     var dataString = 'comsn=' + comsn '&comrn=' + comrn '&compic=' + compic '&comment=' + comment '&eventid=' + eventid '&comuserid=' + comuserid '&owner=' + owner;
      if (comment == '') {
       alert('Must Type Comment to Post Comment');
      }else{
       $("#flash").show();
       $("#flash").fadeIn(400).html('<img src="assets/uploading.gif" />Loading Comment...');
       $.ajax({
        type: "POST",
        url: "comments_post.php",
        data: dataString,
        cache: false,
        success: function (html) {
         $("ol#update").prepend(html);
         $("ol#update li:last").fadeIn("slow");
         $("#flash").hide();
        }
       });
      }return false;
    });
});
</script>
+1  A: 
var dataString = 'comsn=' + comsn + '&comrn=' + comrn + '&compic=' + compic + '&comment=' + comment + '&eventid=' + eventid '&comuserid=' + comuserid + '&owner=' + owner;

You've got a lot of missing +.

Also jquery have a method called serialize which do the same think you are doing by hand probably worth to give a try.

RageZ
thanks for the pointer. It works now, thanks.
Patrick
@Patrick: you are welcome
RageZ
+1  A: 

You have missing + signs in your concatenation:

var dataString = 'comsn=' + comsn + '&comrn=' + comrn +
                 '&compic=' + compic + '&comment=' + comment +
                 '&eventid=' + eventid + '&comuserid=' + comuserid +
                 '&owner=' + owner;

However if you want to get all your form element values in a string of data, you could use the Ajax/serialize method:

var dataString =  $("#formId").serialize();
CMS
+1  A: 

Your missing some +s

+ comrn '&compic='...

should be

+ comrn + '&compic='...
nowk