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.

Seperate them like normal functions e.g.

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

You can also use standard JS like

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

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.

Can you please post the HTML and JS code

<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>

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">

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

<script language="javascript">

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

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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.