SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Enthusiast revelstoke's Avatar
    Join Date
    Sep 2004
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Gurus: Help me out here

    This should be like...incredibly easy and it's not. Here goes. I have a textbox on another page I need to reference. This textbox can, depending on the page, be named 'PartNumber1', 'PartNumber2' etc..all the way up to 10. Now, I have a function which accepts a token called 'id' that holds '1' or '2' which I then need to pass, dynamically, into the line below to reference the input.

    Code:
    window.top.opener.fm.PartNumber1.value = thePn;
    The line above works when you hardcode the number into it, but the second I try to concat the 'id' with 'PartNumber' it blows up. I have tried ALL OF THE FOLLOWING, to no avail...

    Code:
    window.top.opener.fm.PartNumber+id.value = thePn;
    window.top.opener.fm.'PartNumber'+id.value = thePn;
    window.top.opener.fm.concat('PartNumber',id).value = thePn;
    window.top.opener.fm.('PartNumber'+id).value = thePn;
    window.top.opener.fm.eval('PartNumber'+id).value = thePn;
    Why can't I freaking tell it to reference the dang 'PartNumber' CONCAT '1'...I don't get it and this shouldnt be this difficult. I did a simple alert of alert('PartNumber'+id) and it alerted 'PartNumber1' so I know that line, and the ID are getting passed and parsed properly. But as soon as I throw it into the window reference, it can't evaluate it and errors out. HELP!

  2. #2
    SitePoint Enthusiast revelstoke's Avatar
    Join Date
    Sep 2004
    Posts
    41
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Got it. Jesus there are days I loath Javascripts inability to interpret what the coder is trying to do and just run with it. Too many years of VB/VB.Net I guess.

    Solution:

    Code:
    window.top.opener.fm.elements['PartNumber'+theLoc].value = thePn;

  3. #3
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,871
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    JScript's attempting to interpret what the coder is trying to do rather than treating the code literally the way Javascript does is one of the main causes for code that works in modern browsers to not work in IE. I hate it when a browser tries to second guess what my code means because it gets it wrong at least 100.1% of the time and takes ages to work out an alternate way of writing the code that doesn't get misinterpreted.
    Stephen J Chapman

    javascriptexample.net, Book Reviews, follow me on Twitter
    HTML Help, CSS Help, JavaScript Help, PHP/mySQL Help, blog
    <input name="html5" type="text" required pattern="^$">


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
  •