Welcome to the most active Linux Forum on the web.
Go Back > Forums > Non-*NIX Forums > Programming
User Name
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.


  Search this Thread
Old 07-21-2008, 08:26 AM   #1
Registered: Jul 2008
Location: São Paulo - Brazil
Distribution: Fedora 17
Posts: 97

Rep: Reputation: 15
javascript fuction calling trouble... :S

Well, I don't know if JavaScript is actually a programming language... but I couldn't find any better place to post...

The thing is, I have a function been called from an event onFocus and onBlur from the same input...

this function is:

function quantidade_carrinho (campo_qtd, texto_pacote, qtd_pacote, operacao) {
var resultado;

	if (operacao == 1) {
		alert('operacao 1'); //debugging
		resultado = getElementById(campo_qtd).value / qtd_pacote;
		getElementById(texto_pacote).style.visibility = "visible";
	else {
		alert('operacao 2'); //debugging
		resultado = getElementById(campo_qtd).value * qtd_pacote;
		getElementById(texto_pacote).style.visibility = "hidden";
	getElementeById(campo_qtd).value = resultado;
	alert('nenhuma operacao');
and the input code(I added breaklines that doesn't take place in the original code for better visualization here):
<input id="pacote179" name="pacote179" type="hidden" value="15">

<input id="quant179" name="quant179" size="4" value="1"

font-family:tahoma,verdana,arial,helvetica; maxlength=4 

onFocus="quantidade_carrinho ('quant179', 'n_pacote179', '15', 1)"

onBlur="quantidade_carrinho ('quant179', 'n_pacote179', '15', 2)">

<span id="n_pacote179"
The problem is: when I get focus on the input it exececutes both If conditions and don't get any focus...

I tried using boolean values for the variable operacao but didn't work though..

Any help is apreciated...


Last edited by skuzye; 07-21-2008 at 08:30 AM. Reason: bad formatting... corrected
Old 07-21-2008, 09:21 AM   #2
Registered: Jun 2004
Posts: 236

Rep: Reputation: 33
not that i've tested it, but by hiding the element will it get sent the onblur event, likewise because when you show the element you set the value, will it get sent the onfocus event?
Old 07-22-2008, 08:01 AM   #3
Registered: Jul 2008
Location: São Paulo - Brazil
Distribution: Fedora 17
Posts: 97

Original Poster
Rep: Reputation: 15

problem was in the function itself... when changing property of another elemente it DOESN'T get focus! that makes things much easier...

my *.js script, if anybody needs it:

// Atualiza status do msn
function msn_status_update() {
	setTimeout("msn_status_update()", 10000)
	img_suporte.src = img_suporte.src + '?' + (new Date()).getTime();
	img_frank.src = img_frank.src + '?' + (new Date()).getTime();

function quantidade_carrinho(campo_qtd, pacote_qtd, n_pacote, operacao) {
var resultado;
var quantidade=document.getElementById(campo_qtd);
var numdopacote=document.getElementById(pacote_qtd);

	if (operacao==1 && quantidade.value=="1") {"visible";;
	if (operacao==1 && quantidade.value!="1") {"visible";
	if (operacao==2) {"hidden";

	if (resultado!=undefined && resultado!="") {

Last edited by skuzye; 07-22-2008 at 10:09 AM. Reason: fixed..!


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
calling external javascript function in xslt doesn't work in IE mohtasham1983 Programming 6 05-15-2009 02:25 PM
Calling a function in javascript mohtasham1983 Programming 4 03-04-2008 04:13 PM
JavaScript in firefox trouble Reegz Programming 1 09-16-2006 06:04 AM
Trouble calling 'expect' from bash raypen Linux - Software 1 06-01-2006 08:05 PM
calling all C, ASM in trouble orgcandman Programming 1 06-24-2002 02:07 PM > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 12:36 AM.

Main Menu
Write for LQ is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration