Jump to content

Autofill textbox based on selcted option


DarkPrince2005

Recommended Posts

Can somebody please help me with a script? i've got a drop down box in a  form, but i want to auto generate the text in 3 textboxes depending on the selection made. e.g. if option 1 is selected the first textboxes text should be set to 150, and the second 250, and the third should show the sum of the first and second textboxes values.

Link to comment
https://forums.phpfreaks.com/topic/97274-autofill-textbox-based-on-selcted-option/
Share on other sites

check this out...

<html>

<head>

<script type="text/javascript">

function favBrowser()

{

var mylist=document.getElementById("myList");

if(document.getElementById("myList").options.selectedIndex==0)

{

document.getElementById("favorite").value=mylist.options[mylist.selectedIndex].text;

}

else if(document.getElementById("myList").options.selectedIndex==1)

{document.getElementById("favorite1").value=mylist.options[mylist.selectedIndex].text;

}

if(document.getElementById("favorite1").value!="" && document.getElementById("favorite").value!="")

{

//alert(parseInt(document.getElementById("favorite").value )+parseInt(document.getElementById("favorite1").value));

document.getElementById("favorite2").value=parseInt(document.getElementById("favorite").value )+parseInt(document.getElementById("favorite1").value)

 

}

}

</script>

</head>

 

<body>

<form>

Select your favorite browser:

<select id="myList" onchange="favBrowser()">

  <option>100</option>

  <option>200</option>

 

</select>

<p> <input type="text" id="favorite" size="20"></p>

<p> <input type="text" id="favorite1" size="20"></p>

<p> <input type="text" id="favorite2" size="20"></p>

</form>

</body>

 

</html>

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.