using javascript to move text on clicking a button

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Ian Davies

    #1

    using javascript to move text on clicking a button

    I am trying to move some text by clicking a button. When clicked the button
    runs the java script and this will then take the value in the text field and
    add 10 to it to create a new value, this is then used to move the text
    (id=h1) to a new position and to display the new value in a text field. My
    script is below but does not work. Im new to javascrip and there is probably
    something embarasingly obviour that Im missing. Can anyone help
    Ian


    <SCRIPT TYPE="text/javascript">
    <!--
    function move(amount) {
    var texttop=documen t.form2.xh1.val ue;
    var x = new getObj('h1');
    texttop += amount;
    x.style.top = texttop;
    document.form2. xh1.value=textt op;
    }
    // -->
    </SCRIPT>


    <input name="xh1l" type="button" class="BodyText "
    onclick="javasc ript:move(10)" value="<">

    <input name="xh1" type="text" class="BodyText " value="<?php echo
    $row['xh1']; ?>" size="1">

    <div id="h1">some text</div>


  • Evertjan.

    #2
    Re: using javascript to move text on clicking a button

    Ian Davies wrote on 05 aug 2006 in comp.lang.javas cript:
    I am trying to move some text by clicking a button. When clicked the
    button runs the java script and this will then take the value in the
    text field and add 10 to it to create a new value, this is then used
    to move the text (id=h1) to a new position and to display the new
    value in a text field. My script is below but does not work. Im new to
    javascrip and there is probably something embarasingly obviour that Im
    missing. Can anyone help Ian
    >
    >
    <SCRIPT TYPE="text/javascript">
    <!--
    function move(amount) {
    var texttop=documen t.form2.xh1.val ue;
    var x = new getObj('h1');
    texttop += amount;
    x.style.top = texttop;
    document.form2. xh1.value=textt op;
    >}
    // -->
    </SCRIPT>
    >
    >
    <input name="xh1l" type="button" class="BodyText "
    onclick="javasc ript:move(10)" value="<">
    >
    <input name="xh1" type="text" class="BodyText " value="<?php echo
    $row['xh1']; ?>" size="1">
    >
    <div id="h1">some text</div>
    Try this, IE6 tested:

    =============== =============== =======

    <input type='button'
    onclick='move(2 0)'
    value='<'>

    <div id='h1'
    style='position :absolute;top:1 50px;left:150px ;'>
    some text</div>

    <script type='text/javascript'>

    var texttop = 150;
    var h1 = document.getEle mentById('h1');

    function move(amount) {
    texttop += amount;
    h1.style.top = texttop+'px';
    }

    </script>

    =============== =============== =========

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)

    Comment

    Working...