1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

XF 1.5 Adding a bit of javascript to a few select pages

Discussion in 'XenForo Questions and Support' started by outdoorzman, Dec 5, 2015.

  1. outdoorzman

    outdoorzman Member

    I'm creating a couple of custom Xenforo pages and need to add a bit of Javascript to these pages for Paypal ordering. What is the best way to do this?
     
  2. Steve F

    Steve F Well-Known Member

  3. outdoorzman

    outdoorzman Member

    I'm familiar with templates but I don't know how that gets me to Javascript. Can one enter Javascript directly in a template?
     
  4. EQnoble

    EQnoble Well-Known Member

    Yes, think of templates as html documents that you can add pretty much anything you would like to add to a normal html doc, alternatively you can create a .js file and reference it as well.
     
  5. outdoorzman

    outdoorzman Member

    So actually in the process of creating a new Xenforo "page", Xenforo created a new template for me called _page_node.211. I attempted to add my javascript directly to this template in the form:

    PHP:
    <script type="text/javascript">
    <!--
    function 
    Dollar (val) {  // force to valid dollar amount
    var str,pos,rnd=0;
      if (
    val .995rnd 1;  // for old Netscape browsers
      
    str escape (val*1.0 0.005001 rnd);  // float, round, escape
      
    pos str.indexOf (".");
      if (
    pos 0str str.substring (rndpos 3);
      return 
    str;
    }

    function 
    ReadForm (obj1) { // process un-named selects
    var i,amt,des,obj,pos,val;
      
    amt obj1.baseamt.value*1.0;       // base amount
      
    des obj1.basedes.value;           // base description
      
    for (i=0i<obj1.lengthi++) {     // run entire form
        
    obj obj1.elements[i];           // a form element
        
    if (obj.type == "select-one" &&   // just get selects
            
    obj.name == "") {             // must be un-named
          
    pos obj.selectedIndex;        // which option selected
          
    val obj.options[pos].value;   // selected value
          
    pos  val.indexOf ("@");       // price set?
          
    if (pos 0amt val.substring (pos 1)*1.0;
          
    pos  val.indexOf ("+");       // price increment?
          
    if (pos 0amt amt val.substring (pos 1)*1.0;
          
    pos  val.indexOf ("%");       // percent change?
          
    if (pos 0amt amt + (amt val.substring (pos 1)/100.0);
          if (
    des.length == 0des val;
          else 
    des des ", " val;    // accumulate value
        
    }
      }
      
    obj1.item_name.value des;
      
    obj1.amount.value Dollar (amt);
      if (
    obj1.totobj1.tot.value "$" Dollar (amt);
    }
    //-->
    </script>
    But it doesn't seem to work. What am I doing wrong?
     
  6. EQnoble

    EQnoble Well-Known Member

    It's hard to say without seeing it all in context at your site.

    I have a small amount of time at the moment so if you give me admin credentials temporarily at your site I can take a look and see if I can sort out your issue and explain the problem to you.

    Start a convo if you would like.
     

Share This Page