LinuxQuestions.org
Review your favorite Linux distribution.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
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.

Notices


Reply
  Search this Thread
Old 07-21-2008, 09:26 AM   #1
skuzye
Member
 
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:

Code:
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";
		getElementeById(campo_qtd).select();
	}
	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):
Code:
<input id="pacote179" name="pacote179" type="hidden" value="15">

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

style=font-size:11px;
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"
style="font-size:8px;visibility:hidden">
x15
</span>
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...

Skuzye

Last edited by skuzye; 07-21-2008 at 09:30 AM. Reason: bad formatting... corrected
 
Old 07-21-2008, 10:21 AM   #2
rubadub
Member
 
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, 09:01 AM   #3
skuzye
Member
 
Registered: Jul 2008
Location: São Paulo - Brazil
Distribution: Fedora 17
Posts: 97

Original Poster
Rep: Reputation: 15
fixed!!!!

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:

Code:
// 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") {
		numdopacote.style.visibility="visible";
		quantidade.select();
	}
	if (operacao==1 && quantidade.value!="1") {
		numdopacote.style.visibility="visible";
		resultado=quantidade.value/n_pacote;
		quantidade.select();
	}
	if (operacao==2) {
		numdopacote.style.visibility="hidden";
		resultado=quantidade.value*n_pacote;
	}

	if (resultado!=undefined && resultado!="") {
		quantidade.value=resultado;
	}
}
Skuzye

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


Reply


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 03:25 PM
Calling a function in javascript mohtasham1983 Programming 4 03-04-2008 05:13 PM
JavaScript in firefox trouble Reegz Programming 1 09-16-2006 07:04 AM
Trouble calling 'expect' from bash raypen Linux - Software 1 06-01-2006 09:05 PM
calling all C, ASM in trouble orgcandman Programming 1 06-24-2002 03:07 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 08:16 PM.

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