Jump to content

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>

 

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.