SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    without clicking the submit button

    Code:
    <?php
    if ( isset ($_POST['source']) )
    { 
    $source=$_POST['source'];
    }
    else
    { 
    $source=0;
    }
    ?>
    
    <form method="post">
    <input type="text" name="source" value="<?php echo $source ?>">
    <input type="text" name="copy" value="<?php echo $source ?>">
    <input type="submit">
    </form>
    I have the code above,
    If I enter "someText" in the input box "source" and click the submit button,
    "someText" will be seen the input box "copy".

    I like to make it like the following.
    If I enter "someText" in the input box "source",
    "someText" will be simultaneously seen the input box "copy" without clicking the submit button.

  2. #2
    SitePoint Enthusiast
    Join Date
    Mar 2011
    Location
    Bs. As. - Argentina
    Posts
    35
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Arrow

    First of all, i recomend you no to use <input type="submit"> it's better to use <input type="button"> to get more control of what you want to do.

    For copying text you can use a code like this one

    Code JavaScript:
    var oDest = new Object;
    function setCopyEvent()
    {
        try {
        var o = document.getElementById("source");
        o.onkeyup=copyTxt;
        oDest = document.getElementById("copy");
        }catch(anye){
             //catching the error
        }
    }
     
    function copyTxt(e)
    {
        try {
            if (!e)
            {  //ie browser
            var e = window.event;
                    var o = e.srcElement;
            }else{  //gecko
                    var o = e.currentTarget;
            } 
            oDest.value=o.value;
        }catch(anye){
        //error here
        }
    }

    Call the "setCopyEvent()" function on load, it is not tested, but it should work fine.

    See you

  3. #3
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Or if you want to keep things simple, you can just use this after the form. Preferably, at the end of the body, just before the </body> tag.

    Code javascript:
    var source = document.getElementsByName('source')[0];
    source.onkeyup = function () {
        var copy = this.form.elements.copy;
        copy.value = this.value;
    }
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  4. #4
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Thank you, pablogo and paul.
    They work fine.

    Can I call it ajax?

  5. #5
    Unobtrusively zen silver trophybronze trophy
    paul_wilkins's Avatar
    Join Date
    Jan 2007
    Location
    Christchurch, New Zealand
    Posts
    14,687
    Mentioned
    100 Post(s)
    Tagged
    4 Thread(s)
    Quote Originally Posted by dotJoon View Post
    Thank you, pablogo and paul.
    They work fine.

    Can I call it ajax?
    It is not asynchronous and it doesn't send or receive information to a remote server, so no. You would be very wrong to call it ajax.
    Programming Group Advisor
    Reference: JavaScript, Quirksmode Validate: HTML Validation, JSLint
    Car is to Carpet as Java is to JavaScript

  6. #6
    Get my greedy down dotJoon's Avatar
    Join Date
    Apr 2003
    Location
    daejeon, South Korea
    Posts
    2,223
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by paul_wilkins View Post
    It is not asynchronous and it doesn't send or receive information to a remote server, so no. You would be very wrong to call it ajax.
    Thank you for making me getting the concept by your kind explanation.


Bookmarks

Posting Permissions

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