Foros del Web » Programando para Internet » Javascript »

input text sin quitarse el cursor al reset

Estas en el tema de input text sin quitarse el cursor al reset en el foro de Javascript en Foros del Web. Hola, se que me he explicado mal, pero lo que quiero hacer, es, que, en esta web: http://www.addictools.com Si la veis con firefox, al escribid ...
  #1 (permalink)  
Antiguo 01/11/2008, 07:32
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
input text sin quitarse el cursor al reset

Hola, se que me he explicado mal, pero lo que quiero hacer, es, que, en esta web:

http://www.addictools.com

Si la veis con firefox, al escribid una palabra, veréis que sale una cruz para borrar el campo, pero, cuando le has dado a la cruz, en vez de mantenerse el cursor sobre el input, se aleja de el, por lo que tienes que clickar otra vez en el input text, para volver a escribid.

Ahora, miradla en safari, en safari, esto no ocurre, si no que al clickar en la cruz, sigue el cursor en el input.

Este es el código en js:


//----------------------------------------------------------

if (!applesearch) var applesearch = {};

//----------------------------------------------------------

applesearch.init = function ()
{
var srchform = document.getElementById('searchform');

// Paranoia! Make sure we can get the search form before trying anything
if(srchform) {

var srchinput = document.getElementById('query');
labelText = applesearch.getLabelText();

// add applesearch css for non-safari, dom-capable browsers
if ( navigator.userAgent.toLowerCase().indexOf('safari' ) < 0 && document.getElementById ) {
this.clearBtn = false;

// add style sheet if not safari
var dummy = document.getElementById("dummy_css");
if (dummy) dummy.href = "http://www.addictools.com/includes/applesearch.css";

//------------------

// create and attach the span
var r_crnr = document.createElement('span');
r_crnr.className = 'sbox_r'; // IE win doesn't like setAttribute in this case
r_crnr.setAttribute('id','srch_clear');

var fieldsets = srchform.getElementsByTagName('fieldset');
if (fieldsets) {
fieldsets[0].appendChild(r_crnr);
}

// Create and attach a clearing div, keeps Opera happy
var d_clr = document.createElement('div');
d_clr.setAttribute('class','clear');
srchform.appendChild(d_clr);

//------------------

// set our text colors
var labels = srchform.getElementsByTagName('label');

if (labels) {
if (labels[0].currentStyle) {
// must be using IE
labelColor = labels[0].currentStyle.color;
inputColor = srchinput.currentStyle.color;
} else if (document.defaultView.getComputedStyle) {
labelColor = document.defaultView.getComputedStyle(labels[0], null).getPropertyValue('color');
inputColor = document.defaultView.getComputedStyle(srchinput, null).getPropertyValue('color');
}
}

//------------------

// Paranoia again! Make sure the search field exist
if(srchinput) {
// set the placeholder text based off the label
srchinput.value = labelText;
srchinput.style.color = labelColor;

// add some events to the input field
srchinput.onkeyup = function () {
applesearch.onChange('query','srch_clear');
}
srchinput.onfocus = function () {
if (this.value == labelText) {
this.value = '';
this.style.color = inputColor;
}
}
srchinput.onblur = function () {
if (this.value == '') {
this.value = labelText;
this.style.color = labelColor;
}
}
}

// prevent the form being submitted if the input's value is the placeholder (label) text
srchform.onsubmit = function()
{
if(srchinput && srchinput != labelText) {
return true;
} else {
return false;
}
}
} else {
// Paranoia again! Make sure the search field exist
if(srchinput) {
// Using Safari so change some attributes to get the Apple Search field
srchinput.type = 'search';
srchinput.setAttribute('placeholder',labelText);
srchinput.setAttribute('autosave','bsn_srch');
srchinput.setAttribute('results','5');
}
}
}
}

//----------------------------------------------------------

applesearch.getLabelText = function()
{
var srchform = document.getElementById('searchform');
if(srchform) {
var labels = srchform.getElementsByTagName('label');

if (labels) {
var labelFor = labels[0].getAttribute('for');
var labelText = labels[0].firstChild.nodeValue;
} else {
// just in case, set default text
var labelText = '';
}
} else {
// just in case, set default text
var labelText = '';
}
return labelText;
}

//----------------------------------------------------------

// called when on user input - toggles clear fld btn
applesearch.onChange = function (fldID, btnID)
{
// check whether to show delete button
var fld = document.getElementById( fldID );
var btn = document.getElementById( btnID );

if (fld.value.length > 0 && fld.value != labelText && !this.clearBtn) {
btn.className = 'sbox_r_f2';
btn.fldID = fldID; // btn remembers it's field
btn.onclick = this.clearBtnClick;
this.clearBtn = true;
} else if (fld.value.length == 0 && this.clearBtn) {
btn.className = 'sbox_r';
btn.onclick = null;
this.clearBtn = false;
// reset the field's placeholder text
fld.value = '';
fld.style.color = labelColor;
}
}

//----------------------------------------------------------

applesearch.clearFld = function (fldID,btnID)
{
var fld = document.getElementById( fldID );
fld.value = '';
this.onChange(fldID, btnID);
}


//----------------------------------------------------------

applesearch.clearBtnClick = function ()
{
applesearch.clearFld(this.fldID, this.id);
}

//----------------------------------------------------------

window.onload = function () { applesearch.init(); }

//----------------------------------------------------------

Alguien podría ayudarme? Gracias.
  #2 (permalink)  
Antiguo 02/11/2008, 03:11
Avatar de Fernand0  
Fecha de Ingreso: septiembre-2005
Ubicación: Buenos Aires
Mensajes: 610
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: input text sin quitarse el cursor al reset

Wenas.. pusiste mucho codigo.. asi que te digo que hacer no mas...

En la function donde borras el VALUE del input.... pon un .focus()

O sea..

Código PHP:
input.value='';
input.focus(); 
  #3 (permalink)  
Antiguo 02/11/2008, 08:02
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
Respuesta: input text sin quitarse el cursor al reset

Hola, en que parte exactamente lo tengo que poner? Dime entre que parte del código.

Saludos.
  #4 (permalink)  
Antiguo 02/11/2008, 09:41
Avatar de Fernand0  
Fecha de Ingreso: septiembre-2005
Ubicación: Buenos Aires
Mensajes: 610
Antigüedad: 18 años, 7 meses
Puntos: 19
Respuesta: input text sin quitarse el cursor al reset

Código PHP:
applesearch.clearFld = function (fldID,btnID)
{
var 
fld document.getElementByIdfldID );
fld.value '';
this.onChange(fldIDbtnID);
fld.focus();

  #5 (permalink)  
Antiguo 02/11/2008, 14:19
 
Fecha de Ingreso: mayo-2007
Mensajes: 68
Antigüedad: 17 años
Puntos: 0
Respuesta: input text sin quitarse el cursor al reset

Arreglado, gracias. Pero ahora en Safari no sale el botón de borrar una vez que has borrado algo y has vuelto a escribir, se puede ver si va a safari a esta dirección http://www.addictools.com.
Atención: Estás leyendo un tema que no tiene actividad desde hace más de 6 MESES, te recomendamos abrir un Nuevo tema en lugar de responder al actual.
Respuesta




La zona horaria es GMT -6. Ahora son las 16:35.