No announcement yet.

Simple javascript help?

  • Filter
  • Time
  • Show
Clear All
new posts

  • Simple javascript help?

    Ok, let's try this one.

    What I'm trying to do, is have this javascript fire when the user presses a button. The script should get the value of the currently selected item in a listbox then run my cgi script on the server. I've done similar things, but this one keeps giving me 'javascript error!' and I can't figure out what I'm doing wrong. 'promos' is the form name and 'promolist' is the listbox (SELECT) name. Any help out there?
    <script TYPE="text/javascript">
    	function GetPromoDesc()
    	  var pID=document.promos.promolist.selected;
    	  window.location = "./promodesc.exe?pID";
    The HTML code that should fire this function off is:
    <div id="wb_AdvancedButton1" style="position:absolute;left:177px;top:338px;
     width:282px;height:22px;z-index:26" align="center">
    <button id="AdvancedButton1" type="button" onClick="GetPromoDesc" 
    name="AdvancedButton1" style="width:282px;height:22px"><p>
    <font style="font-size:13px" color="#000000" face="Arial">
    Show Full Description</font></p></button></div>
    Joe Byrne
    Last edited by Joe Byrne; 29 Dec 2007, 08:51 PM.
    Software makes Hardware Happen

  • #2
    Hello Joe

    I'm not a javascript wizard but have worked with it a lot in past.

    A few thing (from memory - eg not from research...):

    --var pID=document.promos.promolist.selected;
    1. The actual html code is not included but do keep in mind that Javascript is case sensitive. So if the form is Promos or the list is PromoList, it will fail.

    2. What if promolist is not selected? You click a button which activates this script, so you're not sure the list is selected. I would use:

    if ( document.promos.promolist.selected) {
    var pID=document.promos.promolist.selected;

    3. Try putting this line as well as the second in a Try Catch to get the error location and message. And set an alert to get the PID.

    -- window.location = "./promodesc.exe?pID";
    1. I always used document.location.href but you should at least try document.location instead of window.location. And there is also a document.url (but I'm not sure how that one differs).

    2. I'm not sure if "./" works (i suppose it does) but I always use "../". No idea if it makes a difference but it might.

    -- onClick="GetPromoDesc"
    I would advise to use "javascript:GetPromoDesc();". It probably just style but it make it clear that you're calling the javascript function you defined.

    So far my thoughts. Hope I put something above that helps you resolve the problem.



    • #3
      Originally posted by Joe Byrne View Post
      window.location = "./promodesc.exe?pID";
      Maybe not related with the error but... you probably don't really want to put pID inside quotes.

      -- The universe tends toward maximum irony. Don't push it.

      File Extension Seeker - Metasearch engine for file extensions / file types
      Online TrID file identifier | TrIDLib - Identify thousands of file formats


      • #4
        Thanks Guys for the help, but this one was solved weeks ago. Just didn't get around to saying anything since it didn't seem to be much of a topic here
        Software makes Hardware Happen


        • #5
          Javascript declaration:

          <script language="javascript" type="text/javascript">


          • #6
            If you like you may specifiy the rootfolder like "/cgi-bin/file.exe"

            Since i use ASP.NET this is actually unhandy since locally the webserver add's another folder.

            ASP.NET translates "~/files/files.aspx" to the correct virtual rootfolder.
            For javascript i did a similar thing by holding the virtual folder obtained during pageload in the frameset as OBJECT.
            Makes it easier to obtain this fella over and over.


            • #7
              Ah yes, ./ is the current folder, use ../ if you need one level up.