www.webdeveloper.com
Results 1 to 2 of 2

Thread: Dynamic Variable Names

  1. #1
    Join Date
    Feb 2014
    Posts
    1

    Dynamic Variable Names

    Hi all,

    I have an object named "sitedata". Within it are the followint elements:
    Code:
        sitedata.txt_Forename = '';
        sitedata.txt_Surname = '';
    ...and so on.

    I have matching input elements:
    Code:
        <input type="text" id="txt_Forename">
        <input type="text" id="txt_Forename">
    ...and so on.


    How do i write a piece of JQuery so that when "txt_Forename" is updated, it modifies "settings.txt_Forename".. and so on for a given set of inputs??? My best (not working) guess so far is:
    Code:
        $(function() {
            $("form#BookerDetails :input[type=text]").keyup(function(){
                settings. + $(this).attr('id') = $(this).val();
                alert(settings. + $(this).attr('id'));
            });
        });
    please help!

  2. #2
    Join Date
    Oct 2012
    Location
    Croatia
    Posts
    255
    Maybe something like this:

    HTML Code:
    <!DOCTYPE html>
    <html>
    <head>
       <meta charset="UTF-8" />
       <title>Untitled</title>
       <script type="text/javascript">
          var sitedata = {
             txt_Forename: "",
             update: function(that) {
                this[that.id] = that.value;
             }
          }
       </script>
    </head>
    <body>
       <input type="text" id="txt_Forename" onblur="sitedata.update(this)" />
    </body>
    </html>
    It's not JQuery but this is not JQuery forum also...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles