cancel
Showing results for 
Search instead for 
Did you mean: 

Problem - JavaScript Confirm For PopUp Not Working

Former Member
0 Kudos

Dear All,

I was trying for one popup depending on some condition in View of BSP. The popup doesn't pop on the web page. With debugging I found that the debugger simply pass on from the confirm function. And on web page status bar a warning icon appears.

I am using MVC pattern for the development.Kindly let me know what I am missing here.

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

function ConfirmChoice2()

{

var answer.

answer = confirm("Do You Want To Continue?");

<%= W_POPUPVAL %> = answer;

}

</script>

<%

IF W_POPUPVAL = 1.

W_POPUPRET = 'TRUE'.

ELSE.

W_POPUPRET = 'FALSE'.

ENDIF.

%>

Regards

Sapna Modi

Accepted Solutions (0)

Answers (1)

Answers (1)

rainer_liebisch
Contributor
0 Kudos

Hi Sapna,

have a look at the following thread (the part written by Brian McKellar). There the basic parts of using Javascript variables in BSPs were explained.

Regards,

Rainer

maximilian_schaufler
Active Contributor
0 Kudos

Yes,

this thread is a very good summary of what happens where (server/client).

In general, basic knowledge of HTML, JavaScript and server-side scripting should give you a much easier time dealing with BSP, so check out a few web resources on this.

Just mentioning <a href="http://www.w3schools.com">www.w3schools.com</a> as one example, there a dozens and hundreds more ...

Invest some (a lot of) time in reading and learning, it's worth it!

former_member181879
Active Contributor
0 Kudos

Excellent Rainer! You found exactly the right answer, and just saved me a long night in writing it again. That append we should really save!

brian

Former Member
0 Kudos

Hi Rainer

ThanX for the reply. I have gone through the site. ThanX to Brian also for the detailed explaination on that site.

I understood some basic concepts of JavaScript from the site www.w3schools.com.

And the interaction of ABAP variables with Java script variables is now clear to me to some extent. But that didn't work out in my application. So again I am explaining my problem with some corrections in earlier code.

My Requirements:

1. The confirm popup should come only on some codition like on flag enabling or so. So I have return the code for confirm in <head> tag.

2. In <body>, I am checking the flag which is a model variable and then on its some value, I am calling the JavaScript function for confirm popup.

3. The 'Yes'/'No' of confirm popup has to be picked in any of page varible so that I can use for further processing.

Now, I am not able to get the varible value. The popup is not getting displayed and waring icon appears at the bottom.

<html>

<head>

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

function ConfirmChoice2()

{

var answer.

answer = confirm("Do You Want To Continue?");

document.all.myFlag.value = answer

}

</script>

</head>

<body>

-


-


<%

DATA: flag TYPE STRING.

flag = request->get_form_field( 'myFlag' ).

%>

<input type=hidden name=myFlag value="">

<%

IF MODEL->POPUP_FLG = 'Y'.

%>

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

{

ConfirmChoice2()

}

</script>

<%

if flag = 'TRUE'.

MODEL->POPUP_FLGPROC = 'N'.

else.

MODEL->POPUP_FLGPROC = 'Y'.

endif.

ENDIF.

%>

</body>

</html>

Regards

Sapna

maximilian_schaufler
Active Contributor
0 Kudos

Hi Sapna,

two things that really jumped at me from your descriptions:

*) The warning icon in the status bar informs you about a javascript error - try double-clicking it, at least you can get the line numer of the error, and compare it with the HTML browser source code (not the BSP-source!).

*) The variable your are trying to access via get_form_field never gets submitted anywhere - this has to be done using a HTML form element or a variable in the URL.

In addition to learning javascript you should make yourself comfortable with HTML form elements, form submitting, ...

No offense meant, but these are very basic problems, that one could/should be able to learn by himself, as there are tons of resources on the web on this. And - to be honest - these are not the questions that we like to answer in this forum here, as your problem status has not reached BSP-level so far.

Maybe use this as a recommended study route:

HTML (including CSS) -> HTML using forms -> JavaScript -> Server-Side Scripting

Once you have at least basic knowledge and understanding of all of these concepts, you are ready to get going with BSP, saving yourself (and us) a lot of time.

Once again, didn't mean to be harsh, just take it as an advice ...

Cheers,

Max

Former Member
0 Kudos

Hello Maximilian

Thanx for your kind advice of learning the basics. I am doing that on higher priority but due to dead line for submissin of project I am here on this forum to take advice from you ppl.

Again I guess the varible you are talking about was earlier a form element. But as I couldn't get the way of getting the value of javascript variable into it and then using further so refered the link written by Brian.

And the code now you are looking at is very much taken from his page. Ya I agree I must not have utilized that in the correct manner. So I am here again.

I am not very much aware about HTML events and submitting methods and all as I have used only HTMLB tags in my programs who have their own methods explictly specified by SAP system. And everything is going smooth.

So can you please kindly fwd me some link where I can get the relationship between usage of SAP's HTMLB tags/Model Varibels with JavaScripts?

At moment my purpose is to make this confirm popup work smoothly! By the time I will learn other details of HTML, JavaScript.

I will be very thankful to you for this.

Regards

Sapna

former_member181879
Active Contributor
0 Kudos

Let me give your first problem quickly:


var answer<b>.</b>

The important character is just after the "r". What one has to do, is develop three different personalities.

On one page you are programming ABAP, where code is terminated with a ".", also JavaScript where code is terminated with a ";" character, and <HTML> where there is no concept of lines, etc.

brian

former_member181879
Active Contributor
0 Kudos

Sapna,

We are not going to get past the fact that to really do great things, you will unfortunately at the end of the day have to invest time to understand this technology.

We have now invested time in your problem. One day you must return the investment!

Some short comments:

(1) There is no <form> sequence.

(2) "IF flag = 'TRUE'" will fail because the value is actually 'true'. Very subtle. Change code to be "IF flag CS 'TRUE'". Look in ABAP online help to what does CS (Contain String) do.

(3) After the confirm() JavaScript code, you need to actually return to server with the answer. This is done by submitting the form. (You now did add one?)

Below is a complete example for you to play with. Cut and paste this example onto one BSP page. Save. Activate. Fetch coffee. Close door. Gime 10 points. Test. Test. Do not leave the computer for one hour.

It is not complex. But it is also not easy. Hang around!

brian


<html>
 <body>
   <form name=myFrm>
 
    <%-- add here request counter, just to see interaction --%>
    <% DATA: counter TYPE STRING.
       counter = request->get_form_field( 'counter' ) + 1. %>
    <input type=hidden name=counter value="<%=counter%>">
    <%=counter%>
 
    <%-- first question, are we in dirty state. We simulate. --%>
    <input type=submit name=action value="dirty">
    <input type=submit name=action value="clean">
    <% DATA: action TYPE string.
       action = request->get_form_field( 'action' ). %>
 
    <%-- if dirty, request a pop to confirm --%>
    <input type="hidden" name="save" value="">
    <% IF action = 'dirty'. %>
      <script language="JavaScript" type="text/javascript">
        document.all.save.value = confirm("Save?");
        document.all.myFrm.submit();
      </script>
    <% ENDIF. %>
 
    <%-- if we have confirmed state, we save --%>
    <% IF request->get_form_field( 'save' ) CS 'true'. %>
      <span style="color:green">Saved!</span>
    <% ENDIF. %>
 
   </form>
 </body>
</html>