CodingForums.com

CodingForums.com (http://www.codingforums.com/index.php)
-   JavaScript programming (http://www.codingforums.com/forumdisplay.php?f=2)
-   -   syntax error (http://www.codingforums.com/showthread.php?t=273572)

teedoff 09-19-2012 04:19 PM

syntax error
 
Hi been a long time since I've been here.

I have a bit of js that adds a couple of html elements based on the value of a loop. I have a syntax error and cant spot what I've done wrong.

The error says I'm missing a closing ), but they seems to be all matched. I suspect its my quotes and double quotes, but not sure I know whats wrong with what I have now.

My js:
Code:

  $(document).ready(function(){
  $("##addSMRow").bind("click", function(){
    if($(".sm_row").size() < 3){
    $("##addSMRow").prev().append('<div class="sm_row"><div class="select socialMediaSite"><select name="socialMediaSite">#variables.artistData.socialOptionsNew#</select></div><input type="text" name="socialMediaValue" id="socialMediaValue" value="" /> <a href="##" class="remove_row">#variables.metaData.dsp["removeTxt"]#</a></div>');
    }
    if($(".sm_row").size() == 3){
    $("##addSMRow").hide();
    }
    else{
    $("##addSMRow").show();
    }
    return false;
  });
  if($(".sm_row").size() == 3){
    $("##addSMRow").hide();
  }
  $(".remove_row").live("click", function(){
    $(this).parent().remove();
    $("##addSMRow").show();
    return false;
  });
  });

The line the error is not liking is the fourth line I believe. Thanks for any help with his.

WolfShade 09-19-2012 05:23 PM

Glad to see another CF developer on the site!

What does the IE or FF error console say?

teedoff 09-19-2012 06:16 PM

Sorry forgot to include that. Yep CF here! Not many of us around..lol

Thanks for the assistance.

Timestamp: 9/19/2012 11:41:13 AM
Error: SyntaxError: unterminated string literal
Source File: https://dev.getconquer.com/index.cfm...dingArtistInfo
Line: 672, Column: 41
Source Code:
$("#addSMRow").prev().append().html("<div class='sm_row'><div class='select socialMediaSite'><select name='socialMediaSite'>

xelawho 09-19-2012 06:33 PM

it seems like you may want to try this:

Code:

$("##addSMRow").prev().append('<div class="sm_row"><div class="select socialMediaSite"><select name="socialMediaSite"><cfoutput>#variables.artistData.socialOptionsNew#</cfoutput></select></div><input type="text" name="socialMediaValue" id="socialMediaValue" value="" /> <a href="##" class="remove_row"><cfoutput>#variables.metaData.dsp["removeTxt"]#</cfoutput></a></div>');

teedoff 09-19-2012 06:37 PM

Quote:

Originally Posted by xelawho (Post 1271420)
it seems like you may want to try this:

Code:

$("##addSMRow").prev().append('<div class="sm_row"><div class="select socialMediaSite"><select name="socialMediaSite"><cfoutput>#variables.artistData.socialOptionsNew#</cfoutput></select></div><input type="text" name="socialMediaValue" id="socialMediaValue" value="" /> <a href="##" class="remove_row"><cfoutput>#variables.metaData.dsp["removeTxt"]#</cfoutput></a></div>');

Thanks Xelawho. I'm restricted from using cfoutputs in this manner though. lol We have very strict coding guidelines here and one of our standards says cfoutputs wrap the entire view, so I have an opening one for the first line and a closing one for that last line of every html document we code.

teedoff 09-19-2012 06:39 PM

Crap how stupid am I?? lol its breaking on the hash marks. Escaping them seems to have eliminated my code! Not sure the js works correctly or not, but thanks all!

teedoff 09-19-2012 06:49 PM

Ok well the original issue is fixed, however now I have a new issue. When I click the text to add a row, it does indeed add a row. Upon adding a row, it should display a text link for removing a row. Instead this displays the literal value of the variable.....

So instead of displaying a text link "Remove Row",

it displays:
#variables.metaData.dsp["removeTxt"]#

WolfShade 09-19-2012 07:35 PM

That just means that the code isn't wrapped with <cfoutput></cfoutput>.

Or am I missing something?

teedoff 09-20-2012 02:27 PM

Quote:

Originally Posted by WolfShade (Post 1271443)
That just means that the code isn't wrapped with <cfoutput></cfoutput>.

Or am I missing something?

No the whole document is wrapped with cfoutputs. lol

Thanks for the help. It is now fixed and reworked so I dont have all that crap html inside an append function. If interested, here's the js:

Code:

  $(document).ready(function(){
  $(".addSMRow").bind("click", function(){
    var $socialForms = $(".socialForms");
    if($(".sm_row").size() < 3){
    $(".moreSocial").append($socialForms.html());
    }
    if($(".sm_row").size() > 1){
    $(".remove_row").show()
    }
    if($(".sm_row").size() == 3){
    $(".addSMRow").hide();
    }
    else{
    $(".addSMRow").show();
    }
    return false;
  });
  if($(".sm_row").size() == 3){
    $(".addSMRow").hide();
  }
  $(".remove_row").live("click", function(){
    $(this).parent().remove();
    $(".addSMRow").show();
    return false;
  });
  });



All times are GMT +1. The time now is 02:28 AM.

Powered by vBulletin®
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.