SitePoint Sponsor

User Tag List

Results 1 to 6 of 6
  1. #1
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)

    Variable-thingy-stuff question

    Wow.. Been a while since I started a new thread. Anyhow, I'm now learning JavaScript, which I figure is way overdue, since I know XHTML, CSS, PHP and a little ASP.NET. Anyway, I've come across a problem I need help solve.

    I want to reference a value from a selectbox - like this:

    Code:
    function WindowThingy(fileName, formName, formSelect) {
      var selectId = document.formName.formSelect.selectedIndex;
      var windowUrl = fileName + '?id=' + theid;
      NewWindow(windowUrl, 'WindowThingy', '300', '200');
    }
    Naturally, the code above doesn't work, but I think you understand what I'm trying to do, and can help me fix the darn thing.

    I would be very grateful for any help!
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  2. #2
    SitePoint Evangelist azizur_rahman's Avatar
    Join Date
    Nov 2001
    Location
    London, UK
    Posts
    502
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    The code look correct to me. and will work if you have a global variable name: theid. which is not in this function.. but from your message I take that should have been the selectedid instead.


    changed code:
    Code:
    function WindowThingy(fileName, formName, formSelect) {
      var selectId = document.formName.formSelect.selectedIndex;
      var windowUrl = fileName + '?id=' + selectId;
      NewWindow(windowUrl, 'WindowThingy', '300', '200');
    }
    hope this helps!
    Azizur Rahman
    Web Application Developer

  3. #3
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    oops - missed that one. Code still doesn't work, though.

    The code in itself is incorrect as hell - even I can see that - the code regards "formName" and "formSelect" as names of the elements, instead of variables. That's the problem. I think.
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  4. #4
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    You need eval() which interprets strings concatenated with variable values as objects
    Code:
    var selectId = eval('document.'+formName+'.'+formSelect+'.selectedIndex');
    I should note that the concat operator is the plus sign (+) vs, oh say the period (.) in PHP
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev




  5. #5
    Wanna-be Apple nut silver trophy M. Johansson's Avatar
    Join Date
    Sep 2000
    Location
    Halmstad, Sweden
    Posts
    7,400
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    Originally posted by beetle
    You need eval() which interprets strings concatenated with variable values as objects
    Code:
    var selectId = eval('document.'+formName+'.'+formSelect+'.selectedIndex');
    I should note that the concat operator is the plus sign (+) vs, oh say the period (.) in PHP
    I love you. Thank you so much!
    Mattias Johansson
    Short, Swedish, Web Developer

    Buttons and Dog Tags with your custom design:
    FatStatement.com

  6. #6
    Web-coding NINJA! silver trophy beetle's Avatar
    Join Date
    Jul 2002
    Location
    Dallas, TX
    Posts
    2,900
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Thank you, thank you folks. I'll be here from 8-5 CST M-F for all your javascript needs

    Seriously...no problem. Glad to help.
    beetle a.k.a. Peter Bailey
    blogs: php | prophp | security | design | zen | software
    refs: dhtml | gecko | prototype | phpdocs | unicode | charsets
    tools: ide | ftp | regex | ffdev





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
  •