Focal Point
Changing the Form Action Dynamically

This topic can be found at:
https://forums.informationbuilders.com/eve/forums/a/tpc/f/7971057331/m/7041014722

May 10, 2007, 04:27 PM
Code Digger
Changing the Form Action Dynamically
I have 2 buttons. One for Run other for Save.

On click of Save I need to call save.fex and Run I need to call Run.fex.

Also we know we need to give IBIF_EX as a hidden variable in html code.

Can we change it dynamically based on button clicked.
like

docuent.form.IBIF_EX.value = Run.fex
ELSE
docuent.form.IBIF_EX.value = Save.fex

Thanks,
CD
May 10, 2007, 04:39 PM
Francis Mariani
Yes you can, if you get the syntax right.

This should be done via JavaScript in the onClick event of the appropriate button:

<input type="hidden" name="IBIF_ex">
<input type="button" value="Run" onClick="document.forms[0].IBIF_ex.value = 'RUN'; document.forms[0].submit();">
<input type="button" value="Save" onClick="document.forms[0].IBIF_ex.value = 'SAVE'; document.forms[0].submit();">




Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 10, 2007, 04:56 PM
Francis Mariani
Working example:

<HTML>
<BODY>

<FORM action='/ibi_apps/WFServlet' method="get">
<INPUT type="hidden" name="IBIF_ex">
<INPUT type="text" name="TEXT1">
<INPUT type="button" value="BID1" onClick="document.forms[0].IBIF_ex.value = 'BID1'; document.forms[0].submit();">
<INPUT type="button" value="BID3" onClick="document.forms[0].IBIF_ex.value = 'BID3'; document.forms[0].submit();">
</FORM>

</BODY>
</HTML>



Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 10, 2007, 05:00 PM
Code Digger
Hi,

i did this logic inside a javascript function but on click of function I get a page canr be displayed screen

URL says

http://servername/ibi_apps/undefined

:-(

CD
May 10, 2007, 05:03 PM
Francis Mariani
The URL for running my HTML page is:

http://server-name/approot/demo/runfex1.html

What version of WebFOCUS are you on? Are you using CGI or Servlet?

If it's CGI, the form action should be:

/cgi-bin/ibi_cgi/ibiweb.exe


Francis


Give me code, or give me retirement. In FOCUS since 1991

Production: WF 7.7.05M, Dev Studio, BID, MRE, WebSphere, DB2 / Test: WF 8.1.05M, App Studio, BI Portal, Report Caster, jQuery, HighCharts, Apache Tomcat, MS SQL Server
May 10, 2007, 05:27 PM
Code Digger
Now I am getting another error
I am doing





and in javascript on click of save

document.forms[0].IBIF_ex.value = 'save';
document.forms[0].submit();

Now the browser says

IBIF_ex is either null or not an object.


I am working on 7.1
May 10, 2007, 05:28 PM
Code Digger
quote:
Now I am getting another error
I am doing
INPUT type=hidden name="IBIC_server" value="!IBI.AMP.IBIC_server;"
INPUT type=hidden name="IBIAPP_app" value="!IBI.AMP.IBIAPP_app;"
INPUT type=hidden name="IBIF_ex" value="run"

(I have removed the '<' and '>')
and in javascript on click of save

document.forms[0].IBIF_ex.value = 'save';
document.forms[0].submit();

Now the browser says

"IBIF_ex is either null or not an object."

I am working on 7.1

May 11, 2007, 05:35 AM
<Adesh>
Hi,CD why dont you pass a parameter from onclick event of a button to a single function and based on the parameter excute the respective fex
eg.

< type="button" value="BID1" onClick=execute_fex[save)>Save
< type="button" value="BID3" onClick=execute_fex[run)>Run


function execute_fex(param)
{
if (param == run)
{
url="/ibi_apps/WFServlet?"+"&"+"IBIC_server=EDASERVE"+"&"+"IBIF_ex="+"RUN";
document.getElementById("iframe1").src = url;
}
else
{
put the same code with the other fex name.
}
}

This is just an example cant say it will work or not but this is one of the alternate method.
Regards
Adesh

This message has been edited. Last edited by: <Adesh>,
May 11, 2007, 05:43 AM
Alan B
CD
Have you got more than 1 form on the page? The forms[0] refers to the first form on the page, forms[1] would be the second, etc. The error you are getting suggests that js cannot find IBIF_ex in the first form, FORMS[0].

My preferred method is to utilise unique ids on each element and use the getElementById method, which avoids these issues. So Francis's code would become:
<HTML>
<BODY>
<FORM action='/ibi_apps/WFServlet' method="get" id="myform">
<INPUT type="hidden" name="IBIF_ex" id="canChange">
<INPUT type="text" name="TEXT1">
<INPUT type="button" value="BID1" onClick="document.getElementById('canChange').value = 'BID1';
 document.getElementById('myForm').submit();">
<INPUT type="button" value="BID3" onClick="document.getElementById('canChange').value = 'BID3'; 
document.getElementById('myForm').submit();">
</FORM>
</BODY>
</HTML>



Alan.
WF 7.705/8.007