Home » SQL & PL/SQL » SQL & PL/SQL » Button Problem PL/SQL
Button Problem PL/SQL [message #262873] Tue, 28 August 2007 07:15 Go to next message
tommy1987
Messages: 2
Registered: August 2007
Junior Member
http://rafb.net/p/GOQ6u942.html

Please observe my simple code above. I know what the problem is with this code, I just do not know how to resolve it.

Basically, this is toggling view modes with each page refresh even if the buttons to change view mode was not pressed, the onClick event is being executed. This is because the PL/SQL is not hidden into the event properly and PL/SQL just executes it anyway, is there a way to stop this?

Take a look to fully understand the problem.

Thanks in advance to any responses/resolutions.
Re: Button Problem PL/SQL [message #262892 is a reply to message #262873] Tue, 28 August 2007 08:05 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Oddly, I'm not in the habit of clicking on random links that I come across on the internet.
Re: Button Problem PL/SQL [message #262897 is a reply to message #262873] Tue, 28 August 2007 08:10 Go to previous messageGo to next message
Michel Cadot
Messages: 64102
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator
Are you sure this is a PL/SQL Expert question?
Does not this question better fit in another forum?

By the way, like JRowbottom I don't click on an unknown site link.

Regards
Michel
Re: Button Problem PL/SQL [message #262898 is a reply to message #262897] Tue, 28 August 2007 08:14 Go to previous messageGo to next message
tommy1987
Messages: 2
Registered: August 2007
Junior Member
It is just a website for pasting code, because it does the highlighting to make it easier to read.

It's your perogative.
Re: Button Problem PL/SQL [message #262910 is a reply to message #262898] Tue, 28 August 2007 08:39 Go to previous messageGo to next message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Well, you're the one looking for an answer, and we're the ones saying that we won't look at your code where it is, so I reckon the ball's in your court.

Just wrap it in [code] tags and post it here, unless it's huge.

Assuming that this is some sort of PSP like pl/sql generated web page, I'd say that your escription is more like an HTML/Javascript problem than an Oracle one, but I could be wrong.
Re: Button Problem PL/SQL [message #262917 is a reply to message #262910] Tue, 28 August 2007 08:47 Go to previous messageGo to next message
Maaher
Messages: 7062
Registered: December 2001
Senior Member
Here you go.
   IF (l_view_mode = 'COMPACT')
   THEN
      -- Currently Displaying compact listing
      HTP.p
         (   '<p align="right"><input type="button" value="Extended Listing" '
          || 'name="btn_listing_cm" onClick="'
         );
      l_sql    :=
            'update user_settings set view_setting = '''
         || 'EXTENDED'
         || ''' where username = '''
         || util.get_user_name (cookie)
         || '''';

      EXECUTE IMMEDIATE l_sql;

      IF SQL%ROWCOUNT = 0
      THEN
         l_sql          :=
               'insert into user_settings values ('''
            || util.get_user_name (cookie)
            || ''', '''
            || 'EXTENDED'''
            || ')';

         EXECUTE IMMEDIATE l_sql;

         l_view_mode    := getusersetting (util.get_user_name (cookie));
      END IF;

      HTP.p ('location.reload(true)" /></p>');
   ELSIF (l_view_mode = 'EXTENDED')
   THEN
      -- Currently displaying extended listing
      HTP.p
         (   '<p align="right"><input type="button" value="Compact Listing" '
          || 'name="btn_listing_ex" onClick="'
         );
      l_sql    :=
            'update user_settings set view_setting = '''
         || 'COMPACT'
         || ''' where username = '''
         || util.get_user_name (cookie)
         || '''';

      EXECUTE IMMEDIATE l_sql;

      IF SQL%ROWCOUNT = 0
      THEN
         l_sql          :=
               'insert into user_settings values ('''
            || util.get_user_name (cookie)
            || ''', '''
            || 'COMPACT'''
            || ')';

         EXECUTE IMMEDIATE l_sql;

         l_view_mode    := getusersetting (util.get_user_name (cookie));
      END IF;

      HTP.p ('location.reload(true)" /></p>');
   END IF;


MHE
Re: Button Problem PL/SQL [message #262923 is a reply to message #262917] Tue, 28 August 2007 09:00 Go to previous message
JRowbottom
Messages: 5933
Registered: June 2006
Location: Sunny North Yorkshire, ho...
Senior Member
Are you labouring under the misaprehension that by putting the l_sql declarations and the Execute immediates after the start of the definition of the onClick trigger, and before the end of the onClick trigger that the Execute Immediate will execute when the mouse button is clicked?

If so, then you are badly mistaken. If you have a piece of code generating HTML using the HTP and HTF packages, then there is no interaction between the HTML and the Pl/Sql after the web page is displayed other than the return of parameters on page submission.

what the code you have printed will do is this:

If you enter with l_view_mode = 'COMPACT' then it will
1) Output a line to the Html buffer consisting of the text
<p align="right"><input type="button" value="Extended Listing" name="btn_listing_cm" onClick="

2) Update the database and set the view setting to 'EXTENDED' for the given user
3) If that update didn't change any rows, it will Insert a row with a view_setting of EXTENDED (you could use MERGE for that functionality).
4) Output some more text to the HTML buffer saying
'location.reload(true)" /></p>



If you enter with l_view_mode = 'EXTENDED', then you get exactly the same functionlaity as above, but with 'EXTENDED' replaced with 'COMPACT'

If you look at the HTML you're generating you'll see what I'm saying.

What you need to do is to set a parameter when the user clicks on whatever button is responsible for changing the view, detect that parameter at the back end, and do this processing then - ie you need multiple submit paths from your web page, each of which will invoke different functionality in the back end.

[edited for bad spelling and other incompetancies]

[Updated on: Tue, 28 August 2007 09:01]

Report message to a moderator

Previous Topic: getting oracle sql information from java application
Next Topic: How to use switch case to run either of two select statements?
Goto Forum:
  


Current Time: Fri Dec 02 16:44:53 CST 2016

Total time taken to generate the page: 0.28642 seconds