0

Friends, in my project i'm using onblur event in four text boxes and using that onblur event i wanna call different javascript functions i.e', like first text box onblur="test()" and in second text box onblur="test1()" etc. But only one onblur onblur is calling the function and other onblurs are not working. So pls tell me how can i put more the one onblur event and javascript functions in a single page. Urgent pls.

4
Contributors
8
Replies
20
Views
7 Years
Discussion Span
Last Post by gökhan_1
0

Seperate them like normal functions e.g.

<input onblur="function1(); function2(); function3();" />

You can also use standard JS like

<input onblur="this.value = 'somevalue' />
0

I want to use different javascript functions with different onblur events. For eg:-

<input type="text" onblur="test()"><br/>
<input type="text" onblur="testrun()">

where test() and testrun() are diff. javascript functions.

0
<html>
<script>
function test()
{
document.getElementByID('one').value="2";
}
function testrun()
{
document.getElementByID('two').value="4";
}
</script>
<input type="text" id="one" value=""><br/>
<input type="text" id="two" value="">
<br/><br/>
<input type="text" onblur="test()"><br/>
<input type="text" onblur="testrun()">
</html>
0

Whats the issue? That works fine except that for compatability you might want to change the opening script tag to

<script type="text/javascript" language="javascript">
0

I'm not using only <script>. I'm using

<script language="javascript">
0

I want to use different javascript functions with different onblur events. For eg:-

<input type="text" onblur="test()"><br/>
<input type="text" onblur="testrun()">

where test() and testrun() are diff. javascript functions.

I can see nothing to prevent that from working.

If you need the functions to be aware of which text box called them, then pass this as an argument:

<input type="text" onblur="test(this)"><br/>
<input type="text" onblur="testrun(this)">

The functions might look like this:

function test(textBox){
  if (textBox.value == '') {
    //handle empty string here
  }
  var pattern = /...../; //regular expression representing acceptable user entry
  else if (!textBox.value.match(pattern)) {
    //handle incorrect/out-of-range etc. user entry here
  }
}

Of course, there's a million variations on this theme depending on what you need to check for and the action(s) you need to taks in response to correct/incorrect entries.

Airshow

Edited by Airshow: n/a

0

that kind of worked for mine what i get this in my text field
[object HTMLInputElement]

This question has already been answered. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.