skip to Main Content

I’m using jquery ONCLICK to load a module into a div. The code is below.

<

function shomdes(whrfrm,fboxx) { // Show the description for a select measure.
         // Called from the following modules wih the enumerated whrfrm value: 
         // emm explorm explormx explorm2 explorm2x explorm3 explorm4  explorm4x cmf2me graph1
         //  3     0       0        2        2         3        4         4        0      0

         var vflg = 0;
         var mea = '';   
      
         for( var i=0; i<fboxx.options.length; i++ ) { // Find the selected measure.
           if ( fboxx.options[i].selected && fboxx.options[i].value != '' ) { // Selected and non-blank.
             mea = fboxx.options[i].value; // Get the measure selected to display the description for.
             break;          
           } 
         }

         if ( mea != '' ) {                                 
           $('#graphhere').load('imdesc.cgi?str='+document.Choice.govlevel.value+'~x'+':'+mea+':'+'7x~'+document.Choice.echoice[document.Choice.echoice.selectedIndex].value+':1');               
         } else {
             vflg = lrtMsg('No measure has been selected.','mea'); // A measure must be selected.                                          
           }
  
       }

I call shomdes from a button on the UI. I’ve looked at some of the earlier posts and tried some of the suggestions with no luck. I’ve verified that all parameters are right, and it does enter the ‘if ( mea != ” ) {‘ branch, but does not execute. I’m using this approach elsewhere and it works. There is nothing in the console.

I’ve tried to load a measure description into a div using load() as above and using innerHTML. I felt like the jquery was not loading in the load() case, so I’ve tried using different jquery libraries with no change. On the innerHTML case, I didn’t seem to be able to get the quotes right in the OBJ data part. I expect it to show the description in the div in both cases. But nothing happens. The imdesc module is not loading. Any help will be appreciated. Thanks

2

Answers


  1. Chosen as BEST ANSWER

    DevGuy, I answered this way because my answer was too long for a comment. JavaScript seems to be loading. I am able to verify all parameter values and enter the 'if ( mea != '' ) { ' branch. I don't know how to verify if JQuery is loading, but it seems like it is not loading in that it enters the if block and does nothing after that. And there are no console errors. I also just tried to load a test phrase into the div and nothing happened. I think shomdes is called correctly in that I've traced execution to entry into the if block and verified all parameters being passed to imdesc. I think all variable and element IDs are spelled correctly, and nothing is being flagged in the console. The script is on the same domain, is accessible, and returns the correct data based on using this approach elsewhere in the application I'm working on, and my Apache server is configured to execute CGI scripts. There are no special character in the URL and I've verified that the parameters being passed to the module in the URL are right. Finally I have used alerts and console writes to verify execution up to the load statement and all looks right.


  2. Several things could be causing this issue. I’ll go through some possibilities and how to address them.

    JavaScript and jQuery Load: Make sure that JavaScript and jQuery are being loaded correctly and in the proper order on your page. Verify that jQuery is loaded before you use any jQuery functions. Also, ensure that there are no JavaScript errors in the console that could halt the execution of your script.

    Event Handling: Double-check that your onclick event handler is properly set up and that it calls shomdes() correctly.

    Variable and Element IDs: Make sure that all variable names and element IDs (Choice, govlevel, echoice, graphhere, etc.) are correctly spelled, both in the JavaScript and in the HTML.

    Server-side Script: Ensure that imdesc.cgi is on the same domain, accessible, and that it returns the correct data. Also, make sure the server is configured to execute CGI scripts.

    URL Encoding: Your .load() function constructs a URL with various parameters. Make sure these are URL-encoded if necessary, especially if they can contain special characters. However, this likely isn’t the issue if you aren’t seeing errors in the console.

    Console Log: Add some console log statements to your code to trace its execution.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search