Form working with Javascript

Hi everyone,

It's me again, in doubt. :)

So I have a form at my portal that hhave 3 input fields that are supposed to get numbers. And I want that the product of those fields were set at another field, the field 4.

I've just made some javascript code to do that trick:

function quandoMudar(){
    if(parseInt(terra.value).toString() == 'NaN') terra.value = 0;
    if(parseInt(valor2.value).toString() == 'NaN') valor2.value = 0;
    if(parseInt(valor3.value).toString() == 'NaN') valor3.value = 0;
    
    total.value = parseInt(terra.value) + parseInt(valor2.value) +         parseInt(valor3.value)
}

terra.onkeyup = quandoMudar;
valor2.onkeyup = quandoMudar;
valor3.onkeyup = quandoMudar

Easy. And I've made, also, the HTML to show that:

Terra:<input type="text" id="terra" /><br/>
Agua:<input type="text" id="valor2" /><br/>
Ar:<input type="text" id="valor3" /><br/>
<br/>
Vai Planeta :<input type="text" id="total" />

Thing is: Where the heck do I set those 2 codes?

I mean, I couldn't get where to set them to make them work with my form and the other fields.

Thanks for any directions,

1 Like

Hey Rafael,

You should have a look at this nice example about how to use a javascript library in a form:

http://community.bonitasoft.com/comment/33576#comment-33576

let me know if it helps you

Hi everyone!

So, as promissed, I'm back with the results. :)

I've made what I needed with some javascript code, as following (the data is real, I'll use it that way).

<script>
function quandoMudar(){

 if(parseInt(gravidade.value).toString() == 'NaN') gravidade.value = 1;
    if(parseInt(urgencia.value).toString() == 'NaN') urgencia.value = 1;
    if(parseInt(tendencia.value).toString() == 'NaN') tendencia.value = 1;

gut.value = gravidade.value * urgencia.value * tendencia.value
}

gravidade.onchange = quandoMudar;
urgencia.onchange = quandoMudar;
tendencia.onchange = quandoMudar;
</script>

Gravidade <select id="gravidade">
  <option value="1">Impacto Aceitável</option>
  <option value="2">Impacto Baixo</option>
  <option value="3">Impacto Médio</option>
  <option value="5">Impacto Alto</option>
  <option value="8">Impacto Extremo</option>
</select>
Urgência <select id="urgencia">
  <option value="1">Acima de 1 mês</option>
  <option value="2">Em um mês</option>
  <option value="3">Na quinzena</option>
  <option value="4">Na semana</option>
  <option value="5">Imediato</option>
</select>
Tendência <select id="tendencia">
  <option value="1">Não irá mudar</option>
  <option value="2">Irá piorar em longo prazo</option>
  <option value="3">Irá piorar</option>
  <option value="4">Irá piorar em curto prazo</option>
  <option value="5">Piora rapidamente</option>
</select><br/>
GUT <input type="text" id="gut" />

HOWEVER, there is always something missing...

The fields I have in the javascript code are required into the form that will be sent do next step of my pool...and I just realized that this javascript and HTML stuff will not record anything into my variables. :(

Now I have another problem to solve... and need directions again. :(

Hi everyone!

I've still not found a way to make my Javascript code 'talk' with my Bonita Variables. =/

Diggin on the bonita's website I've found something that maybe will help. It's an answer for a question made about the Bonita 5.9, basically the same question I'm doing now.

Hi,

Javascript has access to your web forms only.
You could have access your form fields values for instance.

If you want to access Bonita remotly, you could use Js to communicate with the REST API over Http.
 
So, anyone have a SAMPLE code about it?

Hi Antoine! (Thanks to Alinka I know how to pronunciate your name properly now =D )

Yes, it's defintely the light I was looking for. And it's easy... to someone used to work with javascript and CSS and HTML... :p

Well, seems like I'll have a few ~ hours~ of work on that but I'll try to build it up and bring the results to the community.

Thanks again. :)

pronounce my name is easy: "An", then just add the "T" and the number "1" pronounced like in english. I will thank Alinka for that ;-). About javascript, I don't have a background as a developper and I figured how to do it for the quick tip, I am sure you can handle that ;-)

Hi once again. :)

Yeah, she pronounced it perfectly. I'm not. Just finished calling you 'Antonio'. =p I'll practice.

About the javascript...didn't got your point about 'quick tip'. It's friday and I'm kinda slow after lunch. =P

I'm trying to figure out a way to get the values set at the javascript and set it to my variables but it will be hard to do, I guess. I will need to study a bit more of javascript and HTML. When I have some answer I'll set it here :)

I keep accepting ANY tip anyone can spare. :)

Thanks.

did you tried to store the variables of your javascript in hidden field widgets ?

... no, actually, not.

I can give it a try, however I'm not quite sure how. But I'll try, hehe.

I have an HTML field that contains all my Javascript code. There are 4 fields and 1 function. I'd need then 4 HTML field widgets and a JS file with the function I guess.

Well, let me start trying and see if I can get something.

Thanks. :)