Announcement

Collapse
No announcement yet.

JavaScript help

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    JavaScript help

    Hi,

    First I would like to thank everybody who takes the time to read and reply to messages on this forum, you really do help!

    I have a limited knowledge of javascript but have managed to write a stock message script with help from this forum, however I would like to add different colours dependent on the returned text can anybody help?

    I have the following script

    <SCRIPT LANGUAGE="JavaScript" Type="text/javascript">
    function StockLevels (pItem)
    <!--
    {
    var strIDs = 'Stock Message: '
    {
    if (pItem >= 5)
    {
    strIDs = 'In Stock - Usually ships in 1-2 days'
    }
    else if (pItem <= 4 && pItem >= 1)
    {
    strIDs = 'In Stock - Usually ships in 4-5 days'
    }
    else if (pItem <= 0)
    {
    strIDs = 'On Order - Usually ships in 10-14 days'
    }
    else
    {
    strIDs = 'Unable to verify stock quantities'
    }
    }
    return strIDs
    }
    //-->
    </script>

    I would like each return text to be a different colour i.e Green, Orange and Red, so that users can see instantly the stock levels.

    Any help would be apreciated.

    Thanks

    Steven
    http://www.wallplates.co.uk

    #2
    Change

    'In Stock - Usually ships in 1-2 days'

    to be

    '<font color="green">In Stock - Usually ships in 1-2 days</font>'

    and do similar for the rest.
    Norman - www.drillpine.biz
    Edinburgh, U K / Bitez, Turkey

    Comment


      #3
      The best way is just wrap your string output in <span> tags and apply a CSS style to the tag:

      Code:
      <SCRIPT LANGUAGE="JavaScript" Type="text/javascript">
      function StockLevels (pItem)
      <!--
      {
      var strIDs = 'Stock Message: '
      {
      if (pItem >= 5)
      {
      strIDs = '<span style="color:green">In Stock - Usually ships in 1-2 days</span>'
      }
      else if (pItem <= 4 && pItem >= 1)
      {
      strIDs = '<span style="color:orange">In Stock - Usually ships in 4-5 days</span>'
      }
      else if (pItem <= 0)
      {
      strIDs = '<span style="color:red">On Order - Usually ships in 10-14 days</span>'
      }
      else
      {
      strIDs = 'Unable to verify stock quantities'
      }
      }
      return strIDs
      }
      //-->
      </script>
      www.gbradley.co.uk
      Web Development, Actinic Patches, Scripts & more

      Comment


        #4
        Once again thanks for all your help.

        Steven
        http://www.wallplates.co.uk

        Comment

        Working...
        X