0

So I have been trying to write functions that combine multiple lines of html so when I call the JS function, that html is put on my webpage. Here is an example of one that I got working :

function buildproduct(prodName, prodID, prodDescription) {
   var data = makeHeader()
   data += "<TABLE style='width:100%' border=1 cellpadding=10>"
   data += "<TR><TD rowspan=3 style='width:30%;text-align:center;vertical-"
   data += "align:middle'>" + makeImage(prodID) + ""
   data += "</TD>"
   data += "<TD>" + makeName(prodName) + "</TD>"
   data += "<TD style='text-align:right'>" + makeID(prodID) + "</TD>"
   data += "</TR>"
   data +="<TR><TD style='text-align:center' colspan=2>" + makeLinkbar(prodID) +  ""
   data += "</TD></TR>"
   data += "<TR><TD colspan=2 >" + makeDescription(prodDescription) + ""
   data += "</TD></TR>"
   data += "</TABLE>"
   data += makeFooter()
   productarea.document.writeln(data)
   productarea.document.close()
}

The above code I have got working. Here is the code that I cant seem to get to work right :

function makeLinkbar(prodID) {
    var data = "<form name="_xclick" target="paypal" action=https://www.paypal.com method="post">"
    data += "<input type="hidden" name="cmd" value="_cart">"
    data += "<input type="hidden" name="business" value="[email protected]">"
    data += "<input type="hidden" name="item_name" value="HTML book">"
    data += "<input type="hidden" name="amount" value="24.99">"
    data += "<input type="hidden" name="item_number" value="12345">"
    data += "<input type="image" src=http://www.paypal.com/en_US/i/btn/sc-but-01.gif border="0" name="submit"alt="Make payments with PayPal - it's fast, free             and secure!">"
    data += "<input type="hidden" name="add" value="1">"
    data += "</form>"
    return(data)
    }

Any ideas why I cant get this function to output the html properly? In fact, its not working at all. Thanks guys!

2
  • 4
    The syntax highlighting in your post makes it pretty obvious that the quotes are off. However, you should consider switching to proper HTML templating for much better readability, maintainability, and separation of concerns. Commented May 8, 2013 at 3:38
  • Try to use a developer tools that have color on text to distinguish the difference of syntax. Commented May 8, 2013 at 3:46

2 Answers 2

7

replace double quotes to single quotes only.

like this.

data += "<input type='hidden' name='cmd' value='_cart'>"
Sign up to request clarification or add additional context in comments.

2 Comments

Thank you Vond Ritz. Glad to finally know
Wow pre. ang hirap ng tanong!.haha
3

You have to escape the double quotes like below

var data = "<form name=\"_xclick\" target=\"paypal\" action=https://www.paypal.com method=\"post\">"

or change the double quotes into single

var data = "<form name='_xclick' target='paypal' action=https://www.paypal.com method='post'>"

Comments

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.