473,325 Members | 2,785 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,325 software developers and data experts.

how to un-focus an element

Dear Developers,

I have a simple question. There's a textbox and an imagebutton on my page.
When I focus on the textbox and hit enter, the imagebutton is being clicked.
However, when I click somewher else on the page and hit enter, the
imagebutton gets clicked again. How can I unfocus the imagebutton?
The script I'm implementing is given below.
Thanks in advance,

Burak

<script language="JavaScript" type="text/javascript">
<!--

function clickButton(strID) {
var pButton = document.getElementById(strID);
if (event && event.which) {
if (event.which == 13) {
pButton.click();
return false;
}
} else if (window.event && window.event.keyCode) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
pButton.click();
return false;
}
}
}

function Buttonclick(strID) {
var textBox = document.getElementById(strID);
if(textBox.value == "")
{
alert('Please enter keyword(s)...');
return false;
}
}

// -->
</script>

private const string OnKeyPressFormatString = "return(clickButton('{0}'));";
private const string OnClickFormatString = "return(Buttonclick('{0}'));";
SearchTextBox.Attributes.Add("onKeyPress",
String.Format(OnKeyPressFormatString, buttonClientID));
SearchImageButton.Attributes.Add("onClick",String. Format(OnClickFormatString,textBoxID));
SearchButton.Attributes.Add("onClick",String.Forma t(OnClickFormatString,textBoxID));

Dec 7 '05 #1
3 4397
Javscript has a focus event, used to move focus from element to element,
divs however can be tricker things to set focus against as focus normally
applies to form elements.

Try something like this:

document.getElementById(yourdivname).focus();

Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Burak Kadirbeyoglu" <bk***********@protel.com.tr> wrote in message
news:Ob****************@TK2MSFTNGP14.phx.gbl...
Dear Developers,

I have a simple question. There's a textbox and an imagebutton on my page.
When I focus on the textbox and hit enter, the imagebutton is being
clicked. However, when I click somewher else on the page and hit enter,
the imagebutton gets clicked again. How can I unfocus the imagebutton?
The script I'm implementing is given below.
Thanks in advance,

Burak

<script language="JavaScript" type="text/javascript">
<!--

function clickButton(strID) {
var pButton = document.getElementById(strID);
if (event && event.which) {
if (event.which == 13) {
pButton.click();
return false;
}
} else if (window.event && window.event.keyCode) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
pButton.click();
return false;
}
}
}

function Buttonclick(strID) {
var textBox = document.getElementById(strID);
if(textBox.value == "")
{
alert('Please enter keyword(s)...');
return false;
}
}

// -->
</script>

private const string OnKeyPressFormatString =
"return(clickButton('{0}'));";
private const string OnClickFormatString = "return(Buttonclick('{0}'));";
SearchTextBox.Attributes.Add("onKeyPress",
String.Format(OnKeyPressFormatString, buttonClientID));

SearchImageButton.Attributes.Add("onClick",String. Format(OnClickFormatString,textBoxID));

SearchButton.Attributes.Add("onClick",String.Forma t(OnClickFormatString,textBoxID));

Dec 7 '05 #2
Well, even if I set the focus on another element, the imagebutton gets
clicked again when I anywhere on the page then press enter again. I want the
function Buttonclick() to run when the focus is on the textbox and the Enter
key pressed without entering any character. Any suggestions?

Burak

"John Timney ( MVP )" <ti*****@despammed.com> wrote in message
news:e7***************@tk2msftngp13.phx.gbl...
Javscript has a focus event, used to move focus from element to element,
divs however can be tricker things to set focus against as focus normally
applies to form elements.

Try something like this:

document.getElementById(yourdivname).focus();

Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Burak Kadirbeyoglu" <bk***********@protel.com.tr> wrote in message
news:Ob****************@TK2MSFTNGP14.phx.gbl...
Dear Developers,

I have a simple question. There's a textbox and an imagebutton on my
page. When I focus on the textbox and hit enter, the imagebutton is being
clicked. However, when I click somewher else on the page and hit enter,
the imagebutton gets clicked again. How can I unfocus the imagebutton?
The script I'm implementing is given below.
Thanks in advance,

Burak

<script language="JavaScript" type="text/javascript">
<!--

function clickButton(strID) {
var pButton = document.getElementById(strID);
if (event && event.which) {
if (event.which == 13) {
pButton.click();
return false;
}
} else if (window.event && window.event.keyCode) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
pButton.click();
return false;
}
}
}

function Buttonclick(strID) {
var textBox = document.getElementById(strID);
if(textBox.value == "")
{
alert('Please enter keyword(s)...');
return false;
}
}

// -->
</script>

private const string OnKeyPressFormatString =
"return(clickButton('{0}'));";
private const string OnClickFormatString =
"return(Buttonclick('{0}'));";
SearchTextBox.Attributes.Add("onKeyPress",
String.Format(OnKeyPressFormatString, buttonClientID));

SearchImageButton.Attributes.Add("onClick",String. Format(OnClickFormatString,textBoxID));

SearchButton.Attributes.Add("onClick",String.Forma t(OnClickFormatString,textBoxID));


Dec 19 '05 #3
browsers behave wierdly when enter is pressed, and asp.net doesn't always
recieve the submit - best thing to do is cancel the enter key out entirely.
Have a read of this thread.

http://groups.google.co.uk/group/mic...8d4820ce9f0e90

--
Regards

John Timney
Microsoft MVP

"Burak Kadirbeyoglu" <bk***********@protel.com.tr> wrote in message
news:ub**************@TK2MSFTNGP11.phx.gbl...
Well, even if I set the focus on another element, the imagebutton gets
clicked again when I anywhere on the page then press enter again. I want
the function Buttonclick() to run when the focus is on the textbox and the
Enter key pressed without entering any character. Any suggestions?

Burak

"John Timney ( MVP )" <ti*****@despammed.com> wrote in message
news:e7***************@tk2msftngp13.phx.gbl...
Javscript has a focus event, used to move focus from element to element,
divs however can be tricker things to set focus against as focus normally
applies to form elements.

Try something like this:

document.getElementById(yourdivname).focus();

Regards

John Timney
ASP.NET MVP
Microsoft Regional Director

"Burak Kadirbeyoglu" <bk***********@protel.com.tr> wrote in message
news:Ob****************@TK2MSFTNGP14.phx.gbl...
Dear Developers,

I have a simple question. There's a textbox and an imagebutton on my
page. When I focus on the textbox and hit enter, the imagebutton is
being clicked. However, when I click somewher else on the page and hit
enter, the imagebutton gets clicked again. How can I unfocus the
imagebutton?
The script I'm implementing is given below.
Thanks in advance,

Burak

<script language="JavaScript" type="text/javascript">
<!--

function clickButton(strID) {
var pButton = document.getElementById(strID);
if (event && event.which) {
if (event.which == 13) {
pButton.click();
return false;
}
} else if (window.event && window.event.keyCode) {
if (event.keyCode == 13) {
event.returnValue = false;
event.cancel = true;
pButton.click();
return false;
}
}
}

function Buttonclick(strID) {
var textBox = document.getElementById(strID);
if(textBox.value == "")
{
alert('Please enter keyword(s)...');
return false;
}
}

// -->
</script>

private const string OnKeyPressFormatString =
"return(clickButton('{0}'));";
private const string OnClickFormatString =
"return(Buttonclick('{0}'));";
SearchTextBox.Attributes.Add("onKeyPress",
String.Format(OnKeyPressFormatString, buttonClientID));

SearchImageButton.Attributes.Add("onClick",String. Format(OnClickFormatString,textBoxID));

SearchButton.Attributes.Add("onClick",String.Forma t(OnClickFormatString,textBoxID));



Dec 19 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Agathe | last post by:
Bonjour, Je souhaite insérer dans une table MySQL des données provenant d'un fichier texte grâce à un script PHP. Mon fichier porte l'extension "txt" et les données sont séparées par des ";'. ...
6
by: Raymond H. | last post by:
Bonjour, Je n'arrive pas à savoir comment lire via vb4 l'adresse d'un favoris dans le dossier des favoris où Internet Explorer place ses favoris. Par exemple, comment fait-on pour afficher l'url...
2
by: Mauro | last post by:
Ciao a tutti! vorrei sapere se qualcuno potrebbe darmi qualche dritta (o se sa dove reperire un tutorial) su come realizzare un trial a tempo, da integrare ad un mio programma per impedirne...
0
by: Mego | last post by:
Sto usando vb6 per creare un file .cub a a partire da una query: LOCATION= d:\Test.cub; SOURCE_DSN = "Provider=MSOLAP.2;Data Source=data-center;Initial Catalog=FoodMart 2000"; CREATECUBE=CREATE...
3
by: pascal Joseph | last post by:
J'ai un formulaire avec un seul champ text appelé "unite" et un bouton. En javascript j'aimerai utiliser un script qui interdise les valeurs de type "char" et soit supérieur à 0 J'ai trouvé...
5
by: Chris | last post by:
Bonjour, Plusieurs fichiers PHP d'un programme open source de compteur de visites viennent de se faire hacker sur mon serveur (hébergement mutualisé chez un fournisseur d'accès). Le hacker a...
3
by: Jorge Gallardo | last post by:
Hola de nuevo a todos... Agradecido a todos los que me habeis solucionado problemas anteriores... Pero como no es novedad, me surge otro. Recientemente buscando, adquiri un codigo para juntar...
1
by: Alex | last post by:
Ciao a tutti, sto sviluppando un applicazione windows, in breve all'interno dello stesso namespace ho un form con una datagrid e un thread che effettua dei controlli e "dovrebbe" caricare i dati...
15
by: Ciudad Tecnópolis | last post by:
Hola, primero que todo mil disculpas por postear una pregunta no relacionada al tema pero se que será muy útil para todos! Actualmente estoy presentando un desarrollo en .NET para una compañía y...
3
by: nano9 | last post by:
Hola gente quisiera que alguien me pudiera ayudar con un problemilla que tengo, resulta que estoy programando en ASP con C# y estoy usando un cadbgrid que se comporta parecido a un datagrid o...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.