Dynamically Change onchange Event by javascript

We come across various time that we need to change the form action according to the Event

Let me provide a simple JavaScript Example which will help you

Here is the javacript code below

<script>

function onchangeaction(v){

if(v==”mango”){

document.getElementById(“mangoabc”).style.display=””;

document.getElementById(“bananaabc”).style.display=”none”;

}

else{

document.getElementById(“bananaabc”).style.display=””;

document.getElementById(“mangoabc”).style.display=”none”;

}

}

</script>

And in the body section code:

<form action=”” method=”POST”>

<select onchange=”onchangeaction(this.value)”>

<option value=””>Select Fruit</option>

<option value=”mango”>Mango</option>

<option value=”banana”>Banana</option>

</select>

<br/>

<select style=”display:none”>

<option value=””>Select Mango</option>

<option value=”Fazli”>Fazli</option>

<option value=”Gopalvog”>Gopalvog</option>

</select>

</br>

<select style=”display:none”>

<option value=”Select Banana”>Select Banana</option>

<option value=”Sagor”>sagor</option>

<option value=”Chinichampa”>chinichampa</option>

</select>

</form>

here is the output of the program

at the main page:

After Selecting Fruit Mango then the output:

after Selecting fruit Banana then the output:

Advertisements
  1. No trackbacks yet.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: