I am trying to run html code inside of a cgi script. Everything works expect for the line of code below. It says I have a syntax error and I do not know why this is.

<< "<input class = 'btn' name = 'calculate' type = 'button' VALUE='Shortest Path' onClick='sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')'>\n"

Thank you.

onClick='sendDataST(document.getElementById('begP').value The statement ends on the second ' mark. Use " to enclose values:

<input class = "btn" name = "calculate" type = "button" VALUE="Shortest Path" onClick="sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')">

onClick='sendDataST(document.getElementById('begP').value The statement ends on the second ' mark. Use " to enclose values:

<input class = "btn" name = "calculate" type = "button" VALUE="Shortest Path" onClick="sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')">

That did not work. It gives me an error when I compile it.

Use escaped double-quote characters (\"):

<< "<input class = \"btn\" name = \"calculate\" type = \"button\" VALUE=\"Shortest Path\" onClick=\"sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')\">\n"

I've changed most of them. I think that the ones I didn't change will be okay, but it's been a while since I've written any HTML. You may need to change them as well.

Use escaped double-quote characters (\"):

<< "<input class = \"btn\" name = \"calculate\" type = \"button\" VALUE=\"Shortest Path\" onClick=\"sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')\">\n"

I've changed most of them. I think that the ones I didn't change will be okay, but it's been a while since I've written any HTML. You may need to change them as well.

That fixed it! Thats awesome I was not aware you could do that and I will keep that in mind in the future, thank you. Do you know if you can call functions such as sendDataST inside of the c++ code. The function resides in the same html code inside of the cpp file as the onClick function above. I am getting an error that says the sendDataST function is not defined which it is. Thanks,

Unless your server is set up to use JavaScript as "server-side" code, JS is generally considered "client-side" code. I know you won't be able to directly call your JS functions from the C++ code.

There may be a library that will allow you to do it, but I don't know.

You have 2 options that I can think of:

  1. Put the JavaScript definition of the function in a support file that you include in the HTML source and send it to the client for execution (using a <script> tag).
    <!--An example from a site I did a long time ago:-->
    <script type="text/javascript" src="/functionSupport.js"></script>
  2. Re-Write the function as a C++ function, call it from the appropriate location, and incorporate the return value into the appropriate part of the string that defines the HTML tag.
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.