Results 1 to 3 of 3

Thread: if statement questions - Javascript

  1. #1
    ELFella is offline Junior Member
    Join Date
    Apr 2007
    Posts
    3

    Question if statement questions - Javascript

    I have been racking my brain trying to get a simple if statement inserted into DetailView.html that can check the a database value to see if it is empty and if so, do something........the reason I am being general about it is because I have multiple conditional statements I would like to put in.

    Example:

    if (database_value == '1')
    {
    code to be executed if condition is true
    }
    else
    {
    code to be executed if condition is not true
    }

    I am not a javascript expert, but where do I need to put my my script code......Can it be inline or do I have to call it externally. What files do I need to look in? Any examples?

    I think one of the issues I am having is working around the database values that are in tables.

    Any help would be greatly appreciated.

    Thanks Erin

  2. #2
    eggsurplus's Avatar
    eggsurplus is offline Sugar Community Member
    Join Date
    Dec 2005
    Location
    Minnesota
    Posts
    2,343

    Default Re: if statement questions - Javascript

    This isn't upgrade safe but...at the top of the DetailView.html put a param like {MY_JAVASCRIPT}. In DetailView.php do your condition. If database_value = 1 then assign your javascript code to run for MY_JAVASCRIPT else assign the other js code for MY_JAVASCRIPT. Either that or put the javascript on the html page and put something like if( {MY_VALUE} == 1 and assign MY_VALUE in the php page. See how variable assignments work in those pages to get a better idea.

  3. #3
    ELFella is offline Junior Member
    Join Date
    Apr 2007
    Posts
    3

    Default Re: if statement questions - Javascript

    Thanks eggsurplus,

    I ended up putting in this code into DetailView.html and it worked like a champ......
    This is figures out if a phone has an extension and adds the Ext: if it is present, if not it types nothing
    I have been fighting with this for a few days and it came down to two ' marks enclosing the database field

    <script type="text/javascript">
    var ext1='0'

    if (ext1 < '{PHONE1EXT_C}')
    {
    document.write("<b>Ext: </b>");
    }
    else
    {
    document.write("");
    }
    </script>

    {PHONE1EXT_C}


    Thanks again,
    Erin

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Similar Threads

  1. Internationalization for Javascript
    By WayneSugar in forum Developer Help
    Replies: 7
    Last Post: 2007-08-07, 09:57 AM
  2. Replies: 1
    Last Post: 2007-03-20, 07:16 PM
  3. Replies: 0
    Last Post: 2006-09-28, 10:31 PM
  4. Internationalization for Javascript
    By WayneSugar in forum Translators
    Replies: 0
    Last Post: 2006-07-24, 07:11 PM
  5. Replies: 4
    Last Post: 2004-10-28, 05:18 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •