why do javascript functions evaluated onload

Question: Any ideas how to NOT trigger the confirmOption function on page load, and only trigger it when the button is clicked?

So in my html body i have:

<Body>
<a href="#" id="btn_YES" onclick="<%="send('YES','" + rm.getAction ("YES") + "'); return (false);"%>" class="actionBtn"><span><span>Yes</span></span></a>&#160;
            <a href="#" id="btn_NO" onclick="<%="send('NO','" + rm.getAction ("NO") + "'); return (false);"%>" class="actionBtn"><span><span>No</span></span></a>&#160;
</Body>

Javascript functions that have been working fine:

function send(button, url) {
    if (opener.document && opener.document.forms[0] && (opener.document.forms[0].elements['sessionToken'] || opener.document.forms[0].elements['screenID']))
         {
                                opener.answer(button, url);
                                window.close();
                            } else { 
                                return false;
                            }
                        }   

getAction and confirmOption(String option) are declared in java. If confirmOption is evaluated, it will output in the console YES or NO

function setConfirm(userSelection){
        if(userSelection="YES") result = "<%=mb.confirmOption("YES")%>"; 
        if(userSelection="NO") result = "<%=mb.confirmOption("NO")%>";
}

When i load the page, why does it print in my console:

YES
NO

, even before i clicked on the button? My breakpoint on java was triggered, so i can see that the method was being evaluated on page load - when it shouldn't because it should be triggered when the button is clicked.

When i clicked on the button, my breakpoint was NOT triggered and i was sent to the relevant page.

Any ideas how to NOT trigger the confirmOption function on page load, and only trigger it when the button is clicked?

Answers


they wont be evaluated onload. They will get evaluated as soon as browser finds them during loading although you can defer evaluation and in the above can you are actually calling the function remove quotes


the confirmOption function is your server-end function ,which must be executed and turned to be a value before your browser-end code,so,maybe you can use an ajax post to the servlet to trigger it ,instead of using it this way.


Need Your Help

Unable to delete registry entry: HKLM\SOFTWARE\IBM\Installation Manager\is64bit

upgrade ibm registrykey ibm-rad

While installing an upgraded development environment that consists of combination of WebSphere 8.5 and Eclipse, my existing development environment (RAD &amp; WebSphere 6) got corrupted. Looks like...

Get the TabHost From Fragment Activity?

android android-fragments tabs

I Have a ClassThat Extends Fragment Like This...

About UNIX Resources Network

Original, collect and organize Developers related documents, information and materials, contains jQuery, Html, CSS, MySQL, .NET, ASP.NET, SQL, objective-c, iPhone, Ruby on Rails, C, SQL Server, Ruby, Arrays, Regex, ASP.NET MVC, WPF, XML, Ajax, DataBase, and so on.