Announcement

Collapse
No announcement yet.

Javascript using actnic variables, help needed!

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

    Javascript using actnic variables, help needed!

    I found a cm/inches/feet converter, and have altered it into a converter for calculating pack sizes for flooring ( see below)

    <TABLE cellSpacing=0 cellPadding=0 width=250 border=0>

    <FORM name=sqmpacks>
    <TBODY>
    <TR>
    <TD>
    <FONT face="Arial Narrow"><INPUT
    onblur=sqmconvert() value=2.54 name=sqm> </FONT><FONT face="Arial Narrow"
    size=-1>sqm</FONT></TD>
    </TR>
    <TR>
    <TD>
    <FONT face="Arial Narrow"><INPUT
    onblur=packsconvert() value=1 name=packs> </FONT><FONT face=Arial
    size=-1>packs</FONT></TD>
    </TR>
    <TR>
    <TD width="50%">
    <p align="center"><input type="button" value="Submit" name="B3"></p>
    </TD>
    </TR></TBODY></FORM></TABLE>

    <SCRIPT language=JavaScript>

    /*
    cm/inch/feet converter - credit must stay intact for use
    By Ada Shimar ada@chalktv.com
    For this script and more,
    Visit http://javascriptkit.com
    */

    function roundit(which){
    return Math.round(which*100)/100
    }

    function sqmconvert(){
    with (document.sqmpacks){
    packs.value = roundit(sqm.value/2.54);
    }
    }

    function packsconvert(){
    with (document.sqmpacks){
    sqm.value = roundit(packs.value*2.54);
    }
    }


    </SCRIPT>
    Now here's the tricky bit, each of the flooring products has a different pack size (sqm), and in the properties tab we created a variable for that figure. Now, instead of having to manually change the pack meterage each time and adding it to each separate product, is it possible to use <actinic:variable name="PackMeterage" /> instead of a number in the calculations so I can just add it to the extended info layout for flooring?! Help would be greatly appreciated!!

    - Suzy
    Flooring Sales Ltd
    Flooring Sales Ltd - Wood and Laminate Flooring Company
    Hadlow Flooring
    Herga Flooring

    #2
    You probably need to use some local php in Actinic to modify the javascript for each of the products. You'd also need to have the javascript then be specific for each product, rather than just loaded once for the page.

    Comment


      #3
      Well, according to my manager we've previously had a flooring calculator working in that way before, however the site was lost along with the calculator years before I started working here..! So I have no idea how whoever made it.. er.. made it! The thing is we have A LOT of products to add this too and I'm just looking for a quick easy solution if there is one! Thanks!

      - Suzy
      Flooring Sales Ltd
      Flooring Sales Ltd - Wood and Laminate Flooring Company
      Hadlow Flooring
      Herga Flooring

      Comment


        #4
        The number of products is immaterial surely, as you'd add it to the product layout and thus all products using said layout would get it as part of that OR you could have a switch (yes/no) that enabled it on a product. Your relatively simple quest is to get the calculator reading the variable content, in fact you could even have a switch that switched on the calc IF you had put a sq.m value in, no need for the yes/no then.

        Comment


          #5
          That's exactly how I'd like it to work Lee! Any suggestions?

          - Suzy
          Flooring Sales Ltd
          Flooring Sales Ltd - Wood and Laminate Flooring Company
          Hadlow Flooring
          Herga Flooring

          Comment


            #6
            Just replace all those 2.54's with

            <actinic:variable name="PackMeterage" selectable="false" />

            And see what happens.

            Although the above will only work on single product per page pages. If you're only using this on Extended Info pages, that should be safe.
            Norman - www.drillpine.biz
            Edinburgh, U K / Bitez, Turkey

            Comment


              #7
              Here's cleaner code:
              Code:
              <form name="sqmpacks">
              <table cellSpacing="0" cellPadding="0" width="250" border="0">
              	<tbody>
              		<tr>
              			<td>
              				<font face="Arial Narrow"><input onblur="sqmconvert(this, <actinic:variable name="PackMeterage" selectable="false" />)" value="<actinic:variable name="PackMeterage" selectable="false" />" name="sqm"> </font>
              				<font face="Arial Narrow" size="-1">sqm</font>
              			</td>
              		</tr>
              		<tr>
              			<td>
              				<font face="Arial Narrow"><input onblur="packsconvert(this, <actinic:variable name="PackMeterage" selectable="false" />)" value="1" name="packs"> </font>
              				<font face="Arial" size="-1">packs</font>
              			</td>
              		</tr>
              		<tr>
              			<td width="50%">
              				<p align="center"><input type="button" value="Calculate" name="B3"></p>
              			</td>
              		</tr>
              	</tbody>
              </table>
              </form>
              
              <script language="JavaScript">
              /*
              cm/inch/feet converter - credit must stay intact for use
              By Ada Shimar ada@chalktv.com
              For this script and more,
              Visit http://javascriptkit.com
              */
              
              function roundit(which){
              	return Math.round(which*100)/100
              }
              
              function sqmconvert(fld, pm){
              	with (fld.form){packs.value = roundit(sqm.value / pm);}
              }
              
              function packsconvert(fld, pm){
              	with (fld.form){sqm.value = roundit(packs.value * pm);}
              }
              </script>
              Note that this (and your original code) has to be placed outside any existing FORM ... /FORM tags (forms can't be nested).

              If you want to use it within a FORM, then delete the lines:

              <form name="sqmpacks">

              and

              </form>

              And it should still work OK.
              Norman - www.drillpine.biz
              Edinburgh, U K / Bitez, Turkey

              Comment


                #8
                Aaaahhhhh!!! I cannot thank you enough! It works a treat!

                - Suzy
                Flooring Sales Ltd
                Flooring Sales Ltd - Wood and Laminate Flooring Company
                Hadlow Flooring
                Herga Flooring

                Comment

                Working...
                X