0

For instance, I'd like to get something like this: in document.write

<form>
            <table>

            <tr>
              <td align="right">Subtotal:</td>
              <td align="left"><form name = "e" id ="e"><input type="text" id="subtotal" /></td>
            </tr>

            <tr>
              <td align="right">Sales Tax:</td>
              <td align="left"><form name = "f" id = "f"><input type="text" id="tax" /></td>
            </tr>

            <tr>
              <td align="right">Total:</td>
              <td align="left"><form name = "g" id = "g"><input type="text" id="total" /></td>
            </tr>

          </table>
    </form>

I tried something like

document.write("paste whole code here");

Didn't work.

j08691
  • 204,283
  • 31
  • 260
  • 272
user3577397
  • 453
  • 3
  • 12
  • 27
  • Why are you wanting to do that? – Tim B James Oct 21 '14 at 14:57
  • 2
    document.write can't be used **after** page load, otherwise it overwrites the whole page. when are you calling `document.write()` ? – DividedByZero Oct 21 '14 at 15:00
  • You can pass any string you want to `document.write`. It can be as long as you want. It's not clear what the problem is. – Felix Kling Oct 21 '14 at 15:02
  • I want to do it to get the values from my script to go into the text field. That's how I got it to work on my last program, is there a way? – user3577397 Oct 21 '14 at 15:02
  • Does this mean you are trying to set the value of an input field? Then this would be more appropriate: http://stackoverflow.com/q/7609130/218196 – Felix Kling Oct 21 '14 at 15:03
  • @ Felix, so could that big chunk of code be a string? Is there a way to pass that as a string and keep the formatting the same? – user3577397 Oct 21 '14 at 15:03
  • Yes, but I wouldn't advice to do so because it makes debugging your code more difficult. – Felix Kling Oct 21 '14 at 15:04
  • Yes Felix, I'm trying to get these values to go in the text fields I specified in the bottom of the program. Currently, when I pressed the add item button in my program, it doesn't do anything. I looked at my old code and it seems like I had everything in document.write, but the formatting looked awful. – user3577397 Oct 21 '14 at 15:04
  • Don't use `document.write`. Use proper DOM manipulation methods as demonstrated in the question I linked to. – Felix Kling Oct 21 '14 at 15:05

1 Answers1

1

For the record I don't encourage the use of document.write. But to answer your question, you simply need to escape the newlines in your string:

    document.write('<form> \
                <table> \
                <tr> \
                  <td align="right">Subtotal:</td> \
                  <td align="left"><form name = "e" id ="e"><input type="text" id="subtotal" /></td> \
                </tr> \
                <tr> \
                  <td align="right">Sales Tax:</td> \
                  <td align="left"><form name = "f" id = "f"><input type="text" id="tax" /></td> \
                </tr> \
                <tr> \
                  <td align="right">Total:</td> \
                  <td align="left"><form name = "g" id = "g"><input type="text" id="total" /></td> \
                </tr> \
              </table> \
        </form>');
j08691
  • 204,283
  • 31
  • 260
  • 272
  • Thank you. Would it be against the rules to link my other question in this comment so you, or others could see what I'm trying to do with my program? – user3577397 Oct 21 '14 at 15:11
  • FYI, I'm checking out the link you sent above, and trying to do it that way first. – user3577397 Oct 21 '14 at 15:12