0

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.

3
Contributors
5
Replies
7
Views
6 Years
Discussion Span
Last Post by Fbody
Featured Replies
  • 1

    [icode]onClick='sendDataST(document.getElementById('begP').value[/icode] The statement ends on the second ' mark. Use " to enclose values: [code]<input class = "btn" name = "calculate" type = "button" VALUE="Shortest Path" onClick="sendDataST(document.getElementById('begP').value + '\n' + document.getElementById('endP').value + '\n')">[/code] Read More

1

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')">
0

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.

0

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.

Edited by Fbody: n/a

0

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,

0

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.

Edited by Fbody: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.