Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 14 of 14
  1. #1
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    WANTED: Simple TEXTBOX & BUTTON that uses math formula

    I'm not a programmer and know absolutely nothing about this stuff, BUT this is probably the EASIEST question to be answered.

    I need a simple text boxt and a button that uses the following logical formula to make a calculation:

    IF(TEXT BOX INPUT>=5800,IF((TEXTBOX INPUT-5000)*0.5<=500,(TEXTBOX INPUT-5000)*0.5,500),TEXTBOX INPUT*0.05)

    When the user types a number into the textbox and clicks the button the answer is given inside the textbox or to the side.

    This can be in either HTML or Java, but I (a non-programmer) will have to change the formula from time to time.

    Considering this information, what is the code for this? Is it better to use HTML or Java? I don't want the formula itself to be visible to the user, so does that make Java more desirable than HTML or vice versa?

    Any help would be MUCH APPRECIATED and I'd be happy to donate if needed.


    -james

  • #2
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,678
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    First you need to learn the difference between Java and JavaScript. I’m not sure which one you mean but both do a completely different job. I suppose you’re thinking in the direction of JavaScript.

    Then you need to understand the difference between HTML and JavaScript. Again, both do a completely different job. HTML is primarily made to mark up text, i. e. to give plain text a meaning so that electronic devices can interpret it and make sense out of it. JavaScript is there to add functionality to otherwise static HTML/text. So, to show the content in a meaningful way you’d use HTML (possibly in conjunction with CSS to give it a cusom look). To make it change dynamically on user input you need JavaScript.

    However, as JS is executed on the client side (in the browser) people will be able to look at the source code and see the formula. So if you don’t want that you’d need to do the calculation on the server, which brings a server side programming language into play, such as PHP, ASP, JSP.

    Now, I have no idea what your obscure math formula depicts. Would you be able to write it in human language?
    Last edited by VIPStephan; 09-08-2010 at 10:49 PM.

  • #3
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    The other problem is unless you use a server side language like php the user will see the formula. And I can assist you but your formula is hard to follow.

  • #4
    The Apostate Apostropartheid's Avatar
    Join Date
    Oct 2007
    Posts
    3,215
    Thanks
    16
    Thanked 265 Times in 263 Posts
    Your formula isn't written in particularly clear (pseudo)-code, so I'll assume you copied and pasted it straight from Excel. Please be concise and use a coding language like PHP to express the issue or use words.

  • #5
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Actually once you posted it was straight from excel, I knew what it was.



    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <title>Untitled Document</title>
    <script language="javascript">
    function doCheck(form)
    {
    if(form.mynumber.value>=5800)
    {
    if(((form.mynumber.value-5000)*0.5)<=500)
    {
    form.myanswer.value=(form.mynumber.value-5000)*.5;
    } else
    {
    form.myanswer.value=500;
    }
    } else
    {
    form.myanswer.value=form.mynumber.value*.05;
    }
    }
    </script>
    </head>
    <body>
    <form name="form1" method="get" action="">
    Number: <input type="text" name="mynumber" /></br>
    Answer:<input type="text" name="myanswer" value="" /></br>
    <input type="button" value="Check" onclick="doCheck(this.form)" />

    </body>
    </html>

  • #6
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Responses to each person

    Quote Originally Posted by Apostropartheid View Post
    Your formula isn't written in particularly clear (pseudo)-code,
    Quote Originally Posted by VIPStephan View Post
    ...difference between Java and JavaScript....[you have to use] PHP, ASP, JSP.
    ...no idea what your obscure math formula depicts. Would you be able to write it in human language?
    Quote Originally Posted by jimhill View Post
    The other problem is unless you use a server side language like php the user will see the formula. ....formula is hard to follow.
    Hey guys! Thanks for all the help with this textbox/button thing. I really appreciate it. I'm going to try and address everybody's comments in one post, so please forgive me for making this reply so long.


    Yeah the formula is from Excel.

    Once again it is:
    IF(TEXT BOX INPUT>=5800,IF((TEXTBOX INPUT-5000)*0.5<=500,(TEXTBOX INPUT-5000)*0.5,500),TEXTBOX INPUT*0.05)

    The basic logic formula is:
    IF(logical test, [value if true], [value if false])=

    Mine is a nested logic formula:
    IF(logical test, [IF(logical test, [value if true], [value if false])], [value if false])=

    In Plain English:
    IF TEXTBOX INPUT is > or = to 5800, AND IF (TEXTBOX INPUT - 5000) X 0.5 is < or = to 500, THEN use this formula (TEXTBOX INPUT - 5000) X 0.5, IF NOT then use 500),AND if all of the blue stuff is false then use TEXTBOX INPUT X 0.5

    Hopefully that helps...


    In regards to whether I can use java or javaSCRIPT. It's the latter. I CAN use javascript and of course html.

    In regards to hiding the formula from the user. I'm not sure about whether I can use a remote host/server/PHP/JSP/ASP/ESPN or whatever you guys were talking about because there are certain rules that I have to follow. I really don't know about this programming stuff, so I just included the rules below.


    Allowed:

    You can use HTML and JavaScript to--
    *Change typeface and font sizes
    *Create different colors
    *Create features such as borders and tables
    *Embed pictures and videos


    Not allowed:

    You can’t use HTML or JavaScript that--
    *Calls remote scripts and pages automatically, such as JavaScript "includes" or "iframes."
    *Changes registry entries or otherwise writes to another person’s computer hard drive.
    *Creates automatic pop-ups except for links that open in a new window when clicked on.
    *Is used to drop or read a cookie on any of our pages.
    *Loads any binary program on another person's computer automatically, except for Flash content.
    *Overwrites any area in the listing outside of the item description area.
    *Manipulates areas outside the listing description, including changing fonts, colors, and backgrounds in areas such as our headers and footers.
    *Posts to scripts on our website automatically.
    *Redirects the user from our website to another web page, such as using the "replace" script.

    So, according to these rules can I use the remote host/PHP/ASP/etc that you guys were talking about?


    ATTN: JIM HILL
    I couldn't get your code to work. It looks good, but has no functionality. Do I need to make changes to the code first? I was wondering if you used an outside host. Maybe that's the problem?

  • #7
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,678
    Thanks
    6
    Thanked 1,009 Times in 982 Posts
    OK, I really think you should elaborate on what this entire thing is supposed to be, i. e. why do you need this and where are you going to use it. Because currently it’s hard to give you a definite answer. It sounds like you would be using the script on some third party website?

  • #8
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    http://www.bransonwebdesign.info/exa...stformula.html

    This uses a javascript function is and is probably not going to work where you have it.

  • #9
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    I was hoping to use it on Ebay, but it looks like it's not working.....

    http://cgi.ebay.com/ws/eBayISAPI.dll...T#ht_500wt_941

    What else can I do? I would really like the customer to make the calculation from within the ebay ad. It would be kind of weird for them to go to another website to do that.

    Any ideas?

  • #10
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Jim Hill,

    I just had the thought that maybe you don't want your code in the ebay ad. I was just doing that as a test. Let me know if you want me to delete the ad. Worst case senario it will expire in 24hrs.

    (858) 200-5417

    -james

  • #11
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    Yeah Ebay wont let you manipulate form fields, it would be a security issue for them. Using the code isnt a problem. If you are talking about a link bringing them to my site I would want to do the form differently so it looks better.

  • #12
    Regular Coder
    Join Date
    Jul 2010
    Posts
    271
    Thanks
    3
    Thanked 40 Times in 40 Posts
    If they will let you use this, maybe it will work.
    Be sure to check and make sure the answers are correct as I will accept no responsibility if they aren't.

    PHP Code:
    <a href="javascript: void(0)" 
       
    onclick="window.open('http://bransonwebdesign.info/examples/testformula.html', 
      'windowname1', 
      'width=220, height=200 top=100 left=100'); 
       return false;"
    >Click Here</a

  • #13
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Thanks for sending that new code to try. Unfortunately, it didn't work either. I got this error message from Ebay:
    "Your listing cannot contain javascript (".cookie", "cookie(", "replace(", IFRAME, META, or includes), cookies or base href."

    I just copied and pasted this error message exactly how it was. To me it looks like a bunch of typos, but I guess that's programmer lingo.

    I know that javascript is allowed, but does the error message say that it's not? Or maybe it's just the HREF part of your code that is bringing up the error message?

    I experimented with some other code I found on the internet--

    This code worked:
    PHP Code:
    <a href="http://www.quackit.com/html/html_help.cfm"target="_blank">HTML Help</a

    This code did not work- I got the same error message:
    PHP Code:
    <!-- Codes by Quackit.com -->
    <
    script type="text/javascript">
    // Popup window code
    function newPopup(url) {
        
    popupWindow window.open(
            
    url,'popUpWindow','height=700,width=800,left=10,top=10,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
    }
    </script>
    <a href="JavaScript:newPopup('http://www.quackit.com/html/html_help.cfm');">Open a popup window</a> 
    This code worked, but it opened it up full size instead of a small pop up like it's supposed to be:

    PHP Code:
    <a href="http://www.quackit.com/common/link_builder.cfm" onclick="basicPopup(this.href);return false">Open a popup window</a
    Hopefully, seeing these results are helpful. I'll keep testing codes as I find them and i'll post the results here.

    Also, are there any other ways the customer can make the calculation without leaving the ebay page or is going to a new webpage/pop up the only way to do it?

  • #14
    New to the CF scene
    Join Date
    Sep 2010
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    This code didn't work (same error message)-
    "Your listing cannot contain javascript (".cookie", "cookie(", "replace(", IFRAME, META, or includes), cookies or base href."

    PHP Code:
    <script language="javascript">
    var 
    popupWindow null;
    function 
    positionedPopup(url,winName,w,h,t,l,scroll){
    settings =
    'height='+h+',width='+w+',top='+t+',left='+l+',scrollbars='+scroll+',resizable'
    popupWindow window.open(url,winName,settings)
    }
    </script>
    <p><a href="http://www.quackit.com/common/link_builder.cfm" onclick="positionedPopup(this.href,'myWindow','500','300','100','200','yes');return false">Positioned Popup</a></p> 

    This code DID WORK!. I think this is promising because this does some kind of calculation from WITHIN the ebay ad. ***Can this be modified into what I need?:

    Click here to view the code in action.

    PHP Code:
    <!-- Begin Size Calculator -->


    <
    SCRIPT language=JavaScript type=text/javascript><!--




    function 
    changeSizes(which) {
        for (var 
    0i<document.clothes.elements.lengthi++) {
            if ((
    document.clothes.elements[i].type == 'select-one')) {
                
    document.clothes.elements[i].selectedIndex which;
            }
     }
     
    }
    // -->
    </SCRIPT>
        <form name="clothes">
          <center>
            <table cellspacing="1" bordercolordark="#FF255C" cellpadding="1" width="440" bgcolor="#ffffff" bordercolorlight="#ffffff" border="1">
              <tbody>
                <tr>
                  <td align="middle">
                    <font size="2">USA</font>
                  </td>
                  <td align="middle">
                    <font size="2">USA-STANDARDIZED</font>
                  </td>
                  <td align="middle">
                    <font size="2">UK/IR</font>
                  </td>
                  <td align="middle">
                    <font size="2">FR/ES/PT</font>
                  </td>
                </tr>
                <tr>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="USA">
                      <option selected>
                        2
                      </option>
                      <option>
                        4
                      </option>
                      <option>
                        6
                      </option>
                      <option>
                        8
                      </option>
                      <option>
                        10
                      </option>
                      <option>
                        12
                      </option>
                      <option>
                        14
                      </option>
                      <option>
                        16
                      </option>
                      <option>
                        18
                      </option>
                      <option>
                        20
                      </option>
                      <option>
                        22
                      </option>
                      <option>
                        24
                      </option>
                    </select>
                  </td>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="USA_Named">
                      <option selected>
                        X-Small
                      </option>
                      <option>
                        X-Small/Small
                      </option>
                      <option>
                        Small
                      </option>
                      <option>
                        Medium
                      </option>
                      <option>
                        Medium
                      </option>
                      <option>
                        Large
                      </option>
                      <option>
                        Large/X-Large
                      </option>
                      <option>
                        X-Large/1X
                      </option>
                      <option>
                        1X/2X
                      </option>
                      <option>
                        2X
                      </option>
                      <option>
                        3X
                      </option>
                      <option>
                        3X
                      </option>
                    </select>
                  </td>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="UK">
                      <option selected>
                        4
                      </option>
                      <option>
                        6
                      </option>
                      <option>
                        8
                      </option>
                      <option>
                        10
                      </option>
                      <option>
                        12
                      </option>
                      <option>
                        14
                      </option>
                      <option>
                        16
                      </option>
                      <option>
                        18
                      </option>
                      <option>
                        20
                      </option>
                      <option>
                        22
                      </option>
                      <option>
                        24
                      </option>
                      <option>
                        26
                      </option>
                    </select>
                  </td>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="France">
                      <option selected>
                        32
                      </option>
                      <option>
                        34
                      </option>
                      <option>
                        36
                      </option>
                      <option>
                        38
                      </option>
                      <option>
                        40
                      </option>
                      <option>
                        42
                      </option>
                      <option>
                        44
                      </option>
                      <option>
                        46
                      </option>
                      <option>
                        50
                      </option>
                      <option>
                        52
                      </option>
                      <option>
                        54
                      </option>
                      <option>
                        56
                      </option>
                    </select>
                  </td>
                </tr>
                <tr>
                  <td colspan="4">
                    <font color="#735803" size="3">&nbsp;<br>
                    </font>
                    <center>
                      <font color="#735803" size="3">SELECT YOUR SIZE TO CALCULATE COMPARISON</font>
                    </center>
                    <font color="#735803" size="3"><br>
                    </font>
                  </td>
                </tr>
                <tr>
                  <td align="middle">
                    <font size="2">DE/NORDIC</font>
                  </td>
                  <td align="middle">
                    <font size="2">IT</font>
                  </td>
                  <td align="middle">
                    <font size="2">AU</font>
                  </td>
                  <td align="middle">
                    <font size="2">JP</font>
                  </td>
                </tr>
                <tr>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="Germany">
                      <option selected>
                        30
                      </option>
                      <option>
                        32
                      </option>
                      <option>
                        34
                      </option>
                      <option>
                        36
                      </option>
                      <option>
                        38
                      </option>
                      <option>
                        40
                      </option>
                      <option>
                        42
                      </option>
                      <option>
                        44
                      </option>
                      <option>
                        46
                      </option>
                      <option>
                        48
                      </option>
                      <option>
                        50
                      </option>
                      <option>
                        52
                      </option>
                    </select>
                  </td>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="Italy">
                      <option selected>
                        36
                      </option>
                      <option>
                        38
                      </option>
                      <option>
                        40
                      </option>
                      <option>
                        42
                      </option>
                      <option>
                        44
                      </option>
                      <option>
                        46
                      </option>
                      <option>
                        48
                      </option>
                      <option>
                        50
                      </option>
                      <option>
                        52
                      </option>
                      <option>
                        54
                      </option>
                      <option>
                        56
                      </option>
                      <option>
                        58
                      </option>
                    </select>
                  </td>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="Australia">
                      <option selected>
                        6
                      </option>
                      <option>
                        8
                      </option>
                      <option>
                        10
                      </option>
                      <option>
                        12
                      </option>
                      <option>
                        14
                      </option>
                      <option>
                        16
                      </option>
                      <option>
                        18
                      </option>
                      <option>
                        20
                      </option>
                      <option>
                        22
                      </option>
                      <option>
                        24
                      </option>
                      <option>
                        26
                      </option>
                      <option>
                        28
                      </option>
                    </select>
                  </td>
                  <td align="middle">
                    <select onchange="changeSizes(this.selectedIndex);" size="1" name="Japan">
                      <option selected>
                        5
                      </option>
                      <option>
                        7
                      </option>
                      <option>
                        9
                      </option>
                      <option>
                        11
                      </option>
                      <option>
                        13
                      </option>
                      <option>
                        15
                      </option>
                      <option>
                        17
                      </option>
                      <option>
                        19
                      </option>
                      <option>
                        21
                      </option>
                      <option>
                        23
                      </option>
                      <option>
                        25
                      </option>
                      <option>
                        27
                      </option>
                    </select>
                  </td>
                </tr>
              </tbody>
            </table>
          </center>
        </form>
        <!-- End Size Calculator --> 
    Last edited by dirtriderfly; 09-10-2010 at 10:23 PM.


  •  

    Tags for this Thread

    Posting Permissions

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