Page 1 of 2 12 LastLast
Results 1 to 10 of 19

Thread: Help In Passing A Value

  1. #1
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Question Help In Passing A Value

    Hi,
    I guess (simply) what I'm trying to do here is pass a value.

    I'd like to take an input from a user, within a FORM, and then later refer to that value - displaying it. This will take place within the one .htm page.

    Do I need to have SUBMITted/POSTed the value from the form first of all?

    I seem to be going around the houses with this one.

    Can anyone help please?

    Thanks in advance,

    N.

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    No, you can use ECMAScript to do it if it's all within that one page.
    Code:
    <input type="text" onchange="document.getElementById('pine').innerHTML = this.value;">
    <!-- ... -->
    <p id="pine">
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  3. #3
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    Good Stuff - Thank you.
    That really helps!

    To take this further.... Would I be looking into the realms of cookies if I wanted to pass the same value outside of the .htm page and into another?

    For example, a user enters their name on a menu page & I wanted to recall that value again within a 'sub'-page ... is this easily achieved?

    Thanks again for your guidance.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    The best thing to do there would be to use a server-side language such as PHP or ASP. But yes, you can use cookies or GET requests (you can read it off the address with ECMAScript).
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default

    I'm having to stick with a client-side approach here.

    "But yes, you can use cookies or GET requests (you can read it off the address with ECMAScript)." ....

    Do you know of a decent cookie example to show passing values between pages... ? Alternatively, are GET requests specific to server-side activity?

    Thanks again,

    N.

  6. #6
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    // cookiefuncs.js
    
    function getCookie(name) {
      var value = document.cookie;
      value = value.substring(value.indexOf(name));
      value = value.substring(value.indexOf("=") + 1);
      value = value.substring(0, value.indexOf(";"));
      return value;
    }
    
    function setCookie(name, value) {
      var orig = document.cookie,
        pos = orig.indexOf(name + "="),
        valuepos = pos + name.length + 1;
      if(pos == -1) document.cookie += name + "=" + value + ";";
      else document.cookie = document.cookie.replace(new RegExp(name + "=[^;]+;"), name + "=" + value + ";");
    }
    Code:
    <script type="text/javascript" src="cookiefuncs.js"></script>
    <!-- ... -->
    <input type="pine" onchange="setCookie(this.name, this.value);">
    Code:
    <script type="text/javascript" src="cookiefuncs.js"></script>
    <script type="text/javascript">
    document.write(getCookie("pine"));
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  7. #7
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    The above will work, but might be limited.

    You may even need to use a database or text files to store data using a serverside language, depending on complexity.
    For example, if other users need to see that data, it can't be a cookie.
    Or if you want to store that data even if they clear cookies.

    I mean... that's fine. But... there are limits, so start looking at php unless you just want a little bit of functionality.

    Especially if you get into passwords or anything, then you will need a lot more than clientside code.
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  8. #8
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    I've already suggested this. The OP cannot use server-side technologies.
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  9. #9
    Join Date
    Mar 2006
    Location
    Illinois, USA
    Posts
    12,164
    Thanks
    265
    Thanked 690 Times in 678 Posts

    Default

    Ah, sorry.

    And... not saying you're wrong... just making it clear that the only secure/fully functional way is to use a serverside language.

    But the above code will mimic some of the features failing that, so, if you can't do serverside, that's a great alternative.

    Just wanted to mention it
    Daniel - Freelance Web Design | <?php?> | <html>| español | Deutsch | italiano | português | català | un peu de français | some knowledge of several other languages: I can sometimes help translate here on DD | Linguistics Forum

  10. #10
    Join Date
    Oct 2005
    Location
    Liverpool, UK
    Posts
    87
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Wink

    Thanks guys.
    Sorry - I am still a relative beginner to all this...

    I have "cookiefuncs.js" saved as a file and the following 2 simple .htm files:

    <html>
    <head>
    <script type="text/javascript" src="cookiefuncs.js"></script>
    </head>
    <body>
    <form>
    <table>
    <tr>
    <td><input type="pine" onchange="setCookie(this.name, this.value);"></td>
    </tr>
    </table>
    <input type="submit" value="Submit!">
    </form>
    </body>
    </html>

    Then,

    <html>
    <head>
    <script type="text/javascript" src="cookiefuncs.js"></script>
    </head>
    <body>
    <script type="text/javascript">
    document.write(getCookie("pine"));
    </script>
    </body>
    </html>

    ..... Can you spot my mistake ??!?!?!?!!!

    Thanks again,

    N.

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
  •