Archive for the ‘ Javascript ’ Category

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