0

Im trying to use document.write in order to create a html element that will link to a function. However I am getting:

SyntaxError: missing ) after argument list"

The document.write is also inside a for loop as it needs to dynamically create links for each piece of data.

standardArray[i] = '<a href ="javascript:void(0);" onclick = "showDetails(null, null, ' + stdata.rows.item(i).Title + ');">' + stdata.rows.item(i).StandardNumber + ' ' + stdata.rows.item(i).Title;
document.write(standardArray[i]);

Any ideas?

3
  • CORNEAL CALCIUM CHELATION is not a proper JavaScript syntax. Commented Jun 24, 2018 at 12:01
  • thats what the value becomes once its stored into the array Commented Jun 24, 2018 at 12:03
  • Try this standardArray[i] = "<a href ='javascript:void(0);' onclick = 'showDetails(null, null, '" + stdata.rows.item(i).Title + "')';>" + stdata.rows.item(i).StandardNumber + " "+ stdata.rows.item(i).Title; Commented Jun 24, 2018 at 12:11

1 Answer 1

1

I assume CORNEAL CALCIUM CHELATION is a string, so you need to format your onclick as follows:

showDetails(null, null, 'CORNEAL CALCIUM CHELATION');

Sign up to request clarification or add additional context in comments.

2 Comments

Could you view my edited code and show how I would be able to make that element a string?
Just put single quotes between inserted string (...)"showDetails(null, null, \'' + stdata.rows.item(i).Title + '\');". Look at \' at the end of string before title variable and at the start of string after it

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.