0

How can I use the variable value inside a Statement? It goes like this:

var skillsSelect = document.getElementById("selUnidade");           
var unidade = skillsSelect.options[skillsSelect.selectedIndex].text;
if ( unidade == "" ) {
    alert("Escolha uma Unidade de Estoque!");
    return false;
}
else
{
    alert("Cheguei!");
    self.opener.document.frmIncluir.id_Unidade.value = unidade; 
}
  • 1
    It's hard to tell what you're asking in this question. Which variable? What statement? What are you trying to do? – jbabey Jan 04 '13 at 15:45
  • I don't get what you mean. Maybe you mean inside if else block? Note that each line of code is a statement. Your code composed of statements – Jobert Enamno Jan 04 '13 at 15:46
  • I guess it might be the bracket notation property accessor: http://stackoverflow.com/questions/2664660/in-javascript-how-do-i-convert-a-string-so-it-can-be-used-to-call-a-property – Mister Henson Jan 04 '13 at 16:00

2 Answers2

0
var message = "Foo Bar " + unidade + " blah blah";
alert(message);
osahyoun
  • 5,173
  • 2
  • 17
  • 15
0

Your value assignment syntax is OK. The problem will be with your code that targets the input on the opener page.

self.opener.document.frmIncluir.id_Unidade.value = unidade; 

On this line, frmIncluir needs to be the form name (not ID) and id_Unidade needs to be the input element name (not ID).

If id_Unidade is the ID you could change it to:

self.opener.document.getElementById("id_Unidade").value = unidade; 
MrCode
  • 63,975
  • 10
  • 90
  • 112