SitePoint Sponsor

User Tag List

Results 1 to 5 of 5
  1. #1
    SitePoint Zealot
    Join Date
    Jun 2002
    Location
    Newcastle, UK
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can you insert the value of a textbox into a function?

    Hi all,

    Would dearly love some help with this problem!!

    I have a select box which updates a hidden field on an 'onchange' event. This works fine. This hidden field basically stores the selected name of an image.

    I also have a textarea with a javascript button alongside which calls a function, this function then writes a small piece of html code to the textarea, for an image. I would like to have this source code in the function include the value of the hidden field!

    Here's the code:

    function imageleft()
    {
    document.getElementById('Text').value=document.getElementById('Text').value+"<img src='' align='left'";
    }

  2. #2
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I'm not sure if I understand the question, but here's a shot...
    Code:
    function imageleft()
    {
      var ta = document.getElementById('Text');
      var hf = document.getElementById('hiddenFieldID');
      if (ta && hf) {
        ta.value = ta.value + "<img src='" + hf.value + "' align='left' />";
      }
    }

  3. #3
    SitePoint Zealot
    Join Date
    Jun 2002
    Location
    Newcastle, UK
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hey Mike - thanks v. much for that, you understood me absolutely fine - for some reason (probably posting the code) the end of my message was missed out but you got the gist.

    I've tried out the code and it works fine except for in Internet Explorer - which as you can tell is pretty imperative! Not sure why, but it works fine in Safari on the Mac , which I was primarily using for testing. I'll keep trying so thanks for your help.

  4. #4
    I'll take mine raw silver trophy MikeFoster's Avatar
    Join Date
    Dec 2002
    Location
    Alabama, USA
    Posts
    2,560
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try this one. Try using the 'name' attribute instead of 'id' (or use both).
    Code:
    function imageleft()
    {
      var ta = document.forms['myTAForm'].myTAName; // TA == textarea
      var hf = document.forms['myHFForm'].myHFName; // HF == hidden field
      if (ta && hf) {
        ta.value = ta.value + "<img src='" + hf.value + "' align='left' />";
      }
    }

  5. #5
    SitePoint Zealot
    Join Date
    Jun 2002
    Location
    Newcastle, UK
    Posts
    128
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Mike - absolutely spot on, thankyou v. much indeed.

    Entropy


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
  •