SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Angry Getting error while using Eval function

    HI to all
    i have code
    function OpenWindow(form ,ctg)
    {

    var v = eval("document.frmdetail."+ ctg+".selectedIndex" )
    //ctg is the name of drop down menu
    // name of drop down menu i.e ctg , is generated on run time
    alert(v);

    }

    i am trying to evaluate using eval function , but getting ';' expected error .


    please tell me how to evaluate this expression ,its urgent ,please please help me

    with Regards
    Aspuser123

  2. #2
    CSS & JS/DOM Adept bronze trophy
    Join Date
    Mar 2005
    Location
    USA
    Posts
    5,482
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Please read Guidelines and Suggestions for Posting on Web Development Forums.

    Don't use eval(). There's no need for it.

    Please show us the code for the form and the code for the function call.
    We miss you, Dan Schulz.
    Learn CSS. | X/HTML Validator | CSS validator
    Dynamic Site Solutions
    Code for Firefox, Chrome, Safari, & Opera, then add fixes for IE, not vice versa.

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    If the variable 'form' is a the name of the form:
    Code:
    var v = document.forms[form].elements[ctg].selectedIndex;
    If the variable 'form' is a reference to the form:
    Code:
    var v = form.elements[ctg].selectedIndex;
    But IE6 won't recognize the dynamically created select unless it has an id attribute equal to ctg. So, you need to add both a name and id attribute to the select.

  4. #4
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi


    when i used the above code ,'var v = form.elements[ctg].selectedIndex;' , it is giving the error elements[...] .selectedIndex is null or not an object
    but on using alert ,value of ctg is coming inside javascript function

    below is the calling code for the above mentioned function

    prhtmllink = prhtmllink & "<select id = """& ctgy & """ name = """& ctgy & """ onchange = ""javascript:OpenWindow(this.form ,'" & ctgy & "');""><option value = """ & cnt & """ > select a Document/Link--</option>"

    (all other option values are generated based on query result)



    please note that above code can be called many times and its not fixed .
    what i have to do is that , i have to dynamically create drop down menus based on the number of categories( ie 'ctgy' in above code) available (which depends upon query result)and as soon as the user
    select something( which are links) in the drop down menu , it should open that link in new window
    as the name of drop down menu is not fixed and it is created at run time ( i have given drop down the same name as of category ) , i just don't don't know how to get the name of drop down menu in javascript function, which is created at run time thats why i have passed that name in javascript function as parameter and trying to get the value of selectedIndex (when user select something), which is not working

    please help

    With Regards
    aspuser123

  5. #5
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    What language is that code with all the ampersands written in? It doesn't look like Javascript or Java or PHP or ASP.
    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="^$">

  6. #6
    SitePoint Member
    Join Date
    Apr 2006
    Posts
    4
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    It is an ASP , very surprised you have never used & in ASP

    Anyhow i have found solution !!

    thanx to all

  7. #7
    Programming Since 1978 silver trophybronze trophy felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, NSW, Australia
    Posts
    16,875
    Mentioned
    25 Post(s)
    Tagged
    1 Thread(s)
    Quote Originally Posted by aspuser123
    It is an ASP , very surprised you have never used & in ASP
    Guess I haven't looked at enough ASP code to come across it before.
    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
  •