1. Advertising
    y u no do it?

    Advertising (learn more)

    Advertise virtually anything here, with CPM banner ads, CPM email ads and CPC contextual links. You can target relevant areas of the site and show ads based on geographical location of the user if you wish.

    Starts at just $1 per CPM or $0.10 per CPC.

JS Challenge!

Discussion in 'JavaScript' started by T0PS3O, Mar 7, 2005.

  1. #1
    For the JS Geeks :)

    If you can change this code:

    http://javascript.internet.com/equivalents/length.html

    ...so it just shows "convert [input type=text] cm to inches [button GO] [input type=text output appears here]" and works as well...

    ...I'll reward you with links!

    Thanks!
     
    T0PS3O, Mar 7, 2005 IP
  2. nullbit

    nullbit Peon

    Messages:
    489
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #2
    Inside head:
    
    <script type="text/javascript">
    <!--
    function cm_to_inch(cm)
    {
      return Math.round(10 * (cm * .39)) / 10;
    }
    //-->
    </script>
    
    Code (markup):
    Inside body:
    <form>
      Convert 
      <input type="text" name="cm" id="cm" />  
      cm to inches 
      <input onclick="document.getElementById('inch').value = cm_to_inch(document.getElementById('cm').value)" type="button" value="Go" />
      <input type="text" name="inch" id="inch" />
    </form>
    
    Code (markup):
     
    nullbit, Mar 7, 2005 IP
  3. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #3
    Legendary!

    I spent 10 minutes and couldn't work it out. PM me if you want a link.

    Thanks!
     
    T0PS3O, Mar 7, 2005 IP
  4. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #4
    How do I put a word inside the button?
     
    T0PS3O, Mar 7, 2005 IP
  5. nullbit

    nullbit Peon

    Messages:
    489
    Likes Received:
    19
    Best Answers:
    0
    Trophy Points:
    0
    #5
    I missed that out. I've edited the post to include the "Go"
     
    nullbit, Mar 7, 2005 IP
    T0PS3O likes this.
  6. T0PS3O

    T0PS3O Feel Good PLC

    Messages:
    13,219
    Likes Received:
    777
    Best Answers:
    0
    Trophy Points:
    0
    #6
    Nullbit is a JS whizz indeed. Sussed it but I ran into problems with my host converting double quotes into singles but nullbit had some clever tricks up his sleeve and fixed it again.

    Check out his SEO tool as well: http://www.webmasterbrain.com/ looks very impressive indeed.
     
    T0PS3O, Mar 7, 2005 IP