Jump to content

How would i do this?


Orionsbelter

Recommended Posts

Ok sorry for the confusion, imagine a four step process: on a page i have the text.

 

Step 1: $20.00 // a price of $20.00 just some text.

Step 2: Textfield with 20.00 // I click it to find it changes to a textfield with the value 20.00 already in it

Step 3: Textfield  with 20.00 i change to 12.00 // I change it to 12.00 as i think 20.00 is too high

Step 4: $12.00 // i now click outside of the texfield which it now changes back to text only this time it says the edited amount.

 

I need help doing this i really am willing to learn javascript i do have books but they don't cover this and i believe i learn better from looking at example code

 

Thank you Thrope for replying :D

 

 

 

Link to comment
Share on other sites

Just because I'm board.

 

<DOCTYPE html>
<html>
    <head>
        <script src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.1/jquery.min.js"></script>
        <script>
            $(document).ready(function() {
                var $fld = $('#fld');
                $fld.click(function() {
                    if (!$fld.hasClass('clicked')) {
                        $fld.html('<input type="text" id="tx" value="'+$fld.html()+'">').addClass('clicked');
                        var $tx = $('#tx');
                        $tx.focus().keyup(function(e) {
                            var key = (e.keyCode ? e.keyCode : e.which);
                            if (key == 13) {
                                $fld.html($tx.val()).removeClass('clicked');
                            }
                        });
                    }
                });
            });
        </script>
    </head>
    <body>
        <div id="fld">$20</div>
    </body>
</html>

 

This does pretty much exactly what you want except the text input turns back into normal content once enter has been hit.

 

PS: It relies on the jQuery framework.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.