Javascript if/else

The following script works fine (i am not familiar with Javascript). I wish to change the para.textcontent to display a form (paypal button). if I inset the form in the para.textconten field it does not work. Any help? I have shown the button code below the script.

<tr>
           <td>
                      <label for="weather">Select the weather type today: </label>
                      <select id="weather">
                          <option value="">--Make a choice--</option>
                              <option value="sunny">Sunny</option>
                              <option value="rainy">Rainy</option>
                              <option value="snowing">Snowing</option>
                              <option value="overcast">Overcast</option>
                       </select>

                       <p></p>

                       <script>
                              const select = document.querySelector('select');
                              const para = document.querySelector('p');

                              select.addEventListener('change', setWeather);

                              function setWeather() {
                                  const choice = select.value;


                                 if (choice === 'sunny') {
                                     para.textContent = 'It is nice and sunny outside today. Wear shorts! Go to the beach, or the park, and get an ice cream.';
                                     } else if (choice === 'rainy') {
                                      para.textContent = 'Rain is falling outside; take a rain coat and an umbrella, and don\'t stay out for too long.';
                                     } else if (choice === 'snowing') {
                                      para.textContent = 'The snow is coming down — it is freezing! Best to stay in with a cup of hot chocolate, or go build a snowman.';
                                     } else if (choice === 'overcast') {
                                     para.textContent = 'It isn\'t raining, but the sky is grey and gloomy; it could turn any minute, so take a rain coat just in case.';
                                     } else {
                                       para.textContent = '';
                                     }
                                  }
                             </script>

                        </td>
                    </tr>

<form target="paypal" action="https://www.paypal.com/cgi-bin/webscr" method="post">
<input type="hidden" name="cmd" value="_s-xclick" />
<input type="hidden" name="hosted_button_id" value="DJUTWCWH7R9FJ" />
<table summary=''>
<tr><td><input type="hidden" name="on0" value="Rack Size" /></td></tr><tr><td><select name="os0">
	<option value="Jr. Enlisted">Jr. Enlisted &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$43.99 USD</option>
	<option value="Sr. Enlisted">Sr. Enlisted &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$45.99 USD</option>
	<option value="Stateroom">Stateroom &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$47.99 USD</option>
	<option value="Submarine Crew">Submarine Crew &nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;$43.99 USD</option>
</select> </td></tr>
</table>
<input type="hidden" name="currency_code" value="USD" />
<br style='line-height: 10px' />
<input type="image" src="https://www.paypalobjects.com/en_US/i/btn/btn_cart_LG.gif" style="width:100px; height:25px;" name="submit" alt="PayPal - The safer, easier way to pay online!" />
<img alt="" border="0" src="https://www.paypalobjects.com/en_US/i/scr/pixel.gif" width="1" height="1" />
</form>

I’ve edited your post for readability. When you enter a code block into a forum post, please precede it with a separate line of three backticks and follow it with a separate line of three backticks to make it easier to read.

You can also use the “preformatted text” tool in the editor (</>) to add backticks around text.

See this post to find the backtick on your keyboard.
Note: Backticks (`) are not single quotes (’).

OK, but how do I insert the form code into the else statement?

This topic was automatically closed 182 days after the last reply. New replies are no longer allowed.