dannymcc
dannymcc

Reputation: 3814

Display message if Javascript doesn't work?

What is the simplest way to display a note in place of what the script would normally output?

I currently have the following code:

<p id="orderBy">
<script type="text/javascript"> 
  <!-- 
  // Array of day names
  var dayNames = ["Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday"];
  var nextWorkingDay = [ 1, 2, 3, 4, 5, 1, 1 ];
  var now = new Date();
  document.write("Order by 5pm today for dispatch on " +
                 dayNames[nextWorkingDay[now.getDay()]]);
  // -->
</script>
</p>

(as per Display tomorrow's name in javascript?)

As an example, the above code outputs the following:

Order by 5pm today for dispatch on Monday

I would like to have the following if for any reason javascript is disabled:

Order by 5pm for next working day dispatch

How can I do this?

Upvotes: 2

Views: 116

Answers (2)

Felix Kling
Felix Kling

Reputation: 816404

Use either<noscript>:

<noscript>
    Order by 5pm for next working day dispatch
</noscript>

or put the text into a normal element and hide it with JavaScript.

Upvotes: 4

&#193;lvaro Gonz&#225;lez
&#193;lvaro Gonz&#225;lez

Reputation: 146450

<p id="orderBy">
<script type="text/javascript"> 
  <!-- 
  // Array of day names
  var dayNames = ["Sunday","Monday","Tuesday","Wednesday",
                "Thursday","Friday","Saturday"];
  var nextWorkingDay = [ 1, 2, 3, 4, 5, 1, 1 ];
  var now = new Date();
  document.write("Order by 5pm today for dispatch on " +
                 dayNames[nextWorkingDay[now.getDay()]]);
  // -->
</script>
<noscript>Order by 5pm for next working day dispatch</noscript>
</p>

Upvotes: 2

Related Questions