0

I'm trying to pass string value to javascript function but it shows syntax error.my code is below

product_row +='<td><input type="text" name="edit_product_type" 
id="edit_product_type_'+this.id_sale_order+'" value="'+this.product_type+'" 
onblur="updateProduct(\'' + this.id_sale_order + '\','edit');" rel="edit" />';

Error

SyntaxError: missing ; before statement
..." onblur="updateProduct(\'' + this.id_sale_order + '\','edit');" rel="edit" />'
gsamaras
  • 71,951
  • 46
  • 188
  • 305
user3655158
  • 1
  • 1
  • 2

5 Answers5

0

Read this answer.

Here is an example:

'<input type="button" onClick="gotoNode(\'' + result.name + '\')" />'

In your case, you probably want to pass edit as a string, so change this

product_row +='<td><input type="text" name="edit_product_type" 
id="edit_product_type_'+this.id_sale_order+'" value="'+this.product_type+'" 
onblur="updateProduct(\'' + this.id_sale_order + '\','edit');" rel="edit" />';

to this

product_row +='<td><input type="text" name="edit_product_type" 
id="edit_product_type_'+this.id_sale_order+'" value="'+this.product_type+'" 
onblur="updateProduct(\'' + this.id_sale_order + '\',\'edit\');" rel="edit" />';

where the escape backslashes were used.

Community
  • 1
  • 1
gsamaras
  • 71,951
  • 46
  • 188
  • 305
0

Check for typos:

either: onblur="updateProduct(\'' + this.id_sale_order + '\',\''+edit+'\');"

or: onblur="updateProduct(\'' + this.id_sale_order + '\',\'edit\');"

depends if edit is meant as variable name or string

bbuecherl
  • 1,609
  • 12
  • 20
0

You need to type correct single quotes in onblur function like,

onblur="updateProduct(\"' + this.id_sale_order + '\",\"edit\");" rel="edit" />

You can use both single and double quotes but make sure you have done them with care

Afzal Ahmad
  • 586
  • 5
  • 20
0

You are missing quotes

    product_row +='<td><input type="text" name="edit_product_type" 
id="edit_product_type_'
+this.id_sale_order
+'" value="'
+this.product_type
+'" onblur="updateProduct(\'' 
+ this.id_sale_order 
+ '\',\'edit\');" rel="edit" />';
Bhushan Kawadkar
  • 28,279
  • 5
  • 35
  • 57
0

If you break down your code you will find the problem at second last row where if you remove the word 'edit' you will not get an error and if you put it in double quotation marks you won't get an error but if you put it in single quotation mark , you will get error

product_row +='<td><input type="text" 
name="edit_product_type" 
id="edit_product_type_'+this.id_sale_order+'"
value="'+this.product_type+'" 
onblur="updateProduct(\'' + this.id_sale_order + '\',

\'edit\');" // the problem is here , so put on 'edit' with \'edit\'

rel="edit" />';
Karim Baidar
  • 677
  • 3
  • 10