how to call a javascript funcation on button click based on the value selected in com

how to call a javascript funcation on button click based on the value selected in com

  
Hi,

I need to call javascript function after a click on submit button based on the value selected in the combobox.Please help me on this logic.


Thanks,
Prahanth
Hi Prashanth.
Do you want to implement all the logic in JavaScript, os some in OutSystems?
If you want to implement only in JS, you can use jQuery to inspect the value in the combobox and have some logic that calls the needed function.
If you want to implement it in OutSystems, you can bind the combobox to a variable and then check that value in OutSystems logic. Then add a call to the action the action RunJavaScript on the HTTPRequesthandler extention.
Hi Prahanth,
 
If you want to do it using javascript, just add a onclick event to the button that calls a function defined by you.
 
To read a value from a combobox you need to do something like this:
 
function myFunction(comboboxId) {
    var combobox = document.getElementById(comboboxId);
    var itemValue = combobox.options[combobox.selectedIndex].value;
}
don't forget to pass the id of the combobox from server side to the javascript function, so javascript knows the generated id of the combobox. To do it, all you have to do is when defining the onclick of the button in Service Studio, pass the widget Id as a parameter.
 
Something like this:
 
"myFunction('" + Combobox.Id + "');"
 
Besides this, if you want to avoid the submit after hitting the button, you have to add a return false to the onclick definition.

You can change the javascript to use jQuery if you want to.
João Batista wrote:
Hi Prahanth,
 
If you want to do it using javascript, just add a onclick event to the button that calls a function defined by you.
 
To read a value from a combobox you need to do something like this:
 
function myFunction(comboboxId) {
    var combobox = document.getElementById(comboboxId);
    var itemValue = combobox.options[combobox.selectedIndex].value;
}
don't forget to pass the id of the combobox from server side to the javascript function, so javascript knows the generated id of the combobox. To do it, all you have to do is when defining the onclick of the button in Service Studio, pass the widget Id as a parameter.
 
Something like this:
 
"myFunction('" + Combobox.Id + "');"
 
Besides this, if you want to avoid the submit after hitting the button, you have to add a return false to the onclick definition.

You can change the javascript to use jQuery if you want to.
 Hi João Batista,

Thank you for the reply
I was able to implement using javascript as you described above.Can you please tell me how to achieve this functionality without javascript as well.Please help me on this

Thanks,
Prashanth 


 
Pedro Cardoso wrote:
Hi Prashanth.
Do you want to implement all the logic in JavaScript, os some in OutSystems?
If you want to implement only in JS, you can use jQuery to inspect the value in the combobox and have some logic that calls the needed function.
If you want to implement it in OutSystems, you can bind the combobox to a variable and then check that value in OutSystems logic. Then add a call to the action the action RunJavaScript on the HTTPRequesthandler extention.
 Hi Pedro Cardoso,

I am new to outsystems.we have just started developing application using outsystems.My requirement is i have a combobox with list of values populated(let say:DEV,QA,PROD) and a submit button.I will select a list item from combobox and click submit button.Each list item will have Urls to dev,qa,production environments.So after button click i need to show the corresponding urls login page in an iframe in the current screen itself.Can you please tell me on how to achieve this without using javascript.

Thanks,
Prashanth

 
Hi again Prashanth.

If you inpect the value of the variable that you have associated with the combobox, it will have the URL of the selected option. You have to take that value and construct an unescaped expression that will construct an iframe object in your screen, using as src the value you've taken form the combobox.

In your expression, you will add something like "<iframe src=" + variable value + ">...

Is it clear to you?

Pedro Cardoso wrote:
Hi again Prashanth.

If you inpect the value of the variable that you have associated with the combobox, it will have the URL of the selected option. You have to take that value and construct an unescaped expression that will construct an iframe object in your screen, using as src the value you've taken form the combobox.

In your expression, you will add something like "<iframe src=" + variable value + ">...

Is it clear to you?
 Hi,
Thanks for your help.I have implemented this functionality
 
Regards,
Prashanth Reddy