By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,776 Members | 1,397 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,776 IT Pros & Developers. It's quick & easy.

need this.blur() help -- running it from a separate function

P: n/a
Hi, is it possible to change a form text field to this.blur() from a
separate function? So, what I want to do is when a button is click it
will runblur(), and cause form input name "xyz" to go into a
this.blur() state so nobody can type into it. Can this be done?
Thanks for anyone's help!

Sincerely,

Alex

Jul 23 '05 #1
Share this Question
Share on Google+
7 Replies


P: n/a
<Ra*********@hotmail.com> skrev i meddelandet
news:11**********************@l41g2000cwc.googlegr oups.com...
Hi, is it possible to change a form text field to this.blur() from a
separate function? So, what I want to do is when a button is click it
will runblur(), and cause form input name "xyz" to go into a
this.blur() state so nobody can type into it. Can this be done?
Thanks for anyone's help!


Pass a reference to the text field to the function:

function runblur(inTextFieldRef){
inTextFieldRef.blur();
}

You could then have:

<form.....>
<input type="text" id="mytext">
<input type="button" onclick="runblur(document.getElementById('mytext') );">
</form>

You'll find the going *much* easier if you take the time to read up on basic
Javascript syntax.

--
Joakim Braun
Jul 23 '05 #2

P: n/a
Ra*********@hotmail.com wrote:
Hi, is it possible to change a form text field to this.blur() from a
separate function? So, what I want to do is when a button is click it
will runblur(), and cause form input name "xyz" to go into a
this.blur() state so nobody can type into it. Can this be done?
Thanks for anyone's help!

Sincerely,

Alex


If you want a text input that the user can't modify, use the
'readonly' attribute:

<input type="text" size="20" value="blah blah" readonly>

Using blur() in the manner you suggest will likely cause you
problems - blur() is not a state, it is a method.
--
Rob
Jul 23 '05 #3

P: n/a
Joakim Braun wrote:
<Ra*********@hotmail.com> skrev i meddelandet
news:11**********************@l41g2000cwc.googlegr oups.com...
Hi, is it possible to change a form text field to this.blur() from a
separate function? So, what I want to do is when a button is click it
will runblur(), and cause form input name "xyz" to go into a
this.blur() state so nobody can type into it. Can this be done?
Thanks for anyone's help!

Pass a reference to the text field to the function:

function runblur(inTextFieldRef){
inTextFieldRef.blur();
}


Ignoring that the concept of burring an input in order to mimic
setting the readonly attribute true seems flawed from the start.

Anyhow, a better function is:

function runblur(inTextFieldRef){
if ( inTextFieldRef.blur ) {
inTextFieldRef.blur();
}
}

You can't assume all browsers support all methods for all
elements.

You could then have:

<form.....>
<input type="text" id="mytext">
<input type="button" onclick="runblur(document.getElementById('mytext') );">
</form>


This is hardly a test of the function: the act of clicking on
the second input will cause 'mytext' to blur anyway. A better
test is:

<input type="text" onclick="callBlur(this);" value="Blur me">

<script type="text/javascript">
function runblur() {
// as above
}

function callBlur(x){
runblur(x);
}
</script>

--
Zif
Jul 23 '05 #4

P: n/a

Joakim Braun wrote:
<Ra*********@hotmail.com> skrev i meddelandet
news:11**********************@l41g2000cwc.googlegr oups.com...
Hi, is it possible to change a form text field to this.blur() from a separate function? So, what I want to do is when a button is click it will runblur(), and cause form input name "xyz" to go into a
this.blur() state so nobody can type into it. Can this be done?
Thanks for anyone's help!
Pass a reference to the text field to the function:

function runblur(inTextFieldRef){
inTextFieldRef.blur();
}

You could then have:

<form.....>
<input type="text" id="mytext">
<input type="button"

onclick="runblur(document.getElementById('mytext') );"> </form>

You'll find the going *much* easier if you take the time to read up on basic Javascript syntax.

--
Joakim Braun


.........Sorry, I should have given more information - the attribute I
want to mimic is: <input type="text" id="mytext"
onfocus="this.blur();">, so when that function is called "mytext" will
onfocus blur and behave that way. Can this weird function be done?
Sincerely--- Alex.

Jul 23 '05 #5

P: n/a

RobG wrote:
Ra*********@hotmail.com wrote:
Hi, is it possible to change a form text field to this.blur() from a separate function? So, what I want to do is when a button is click it will runblur(), and cause form input name "xyz" to go into a
this.blur() state so nobody can type into it. Can this be done?
Thanks for anyone's help!

Sincerely,

Alex


If you want a text input that the user can't modify, use the
'readonly' attribute:

<input type="text" size="20" value="blah blah" readonly>

Using blur() in the manner you suggest will likely cause you
problems - blur() is not a state, it is a method.
--
Rob

Hi there. In my situation I want to cause that method to happen via a
remote function(), from an iframe. Do you know how to do this?

Alex

Jul 23 '05 #6

P: n/a
Ra*********@hotmail.com wrote:
RobG wrote:

[...]

If you want a text input that the user can't modify, use the
'readonly' attribute:

<input type="text" size="20" value="blah blah" readonly>

Using blur() in the manner you suggest will likely cause you
problems - blur() is not a state, it is a method.
--
Rob


Hi there. In my situation I want to cause that method to happen via a
remote function(), from an iframe. Do you know how to do this?


"that method" being making the input readonly?

<form action="">
<input type="text" size="20" name="zz">zz<br>
<input type="button" value="Make zz readonly" onclick="
if (this.form.zz.readOnly) {
this.form.zz.readOnly = false;
this.value = 'Make zz readonly';
} else {
this.form.zz.readOnly = true;
this.value = 'Make zz editable';
}
">
</form>

--
Rob
Jul 23 '05 #7

P: n/a

RobG wrote:
Ra*********@hotmail.com wrote:
RobG wrote:

[...]

If you want a text input that the user can't modify, use the
'readonly' attribute:

<input type="text" size="20" value="blah blah" readonly>

Using blur() in the manner you suggest will likely cause you
problems - blur() is not a state, it is a method.
--
Rob


Hi there. In my situation I want to cause that method to happen via a remote function(), from an iframe. Do you know how to do this?


"that method" being making the input readonly?

<form action="">
<input type="text" size="20" name="zz">zz<br>
<input type="button" value="Make zz readonly" onclick="
if (this.form.zz.readOnly) {
this.form.zz.readOnly = false;
this.value = 'Make zz readonly';
} else {
this.form.zz.readOnly = true;
this.value = 'Make zz editable';
}
">
</form>

--
Rob


Exceptional, Rob! It works.

--Alex

Jul 23 '05 #8

This discussion thread is closed

Replies have been disabled for this discussion.