-
December 19th, 2013, 09:37 AM
#1
How to load value to text field when choose value in select
Hi every one, I have problem need help that, I have a form have 1 select filed and 1 text field, I want when I choose value in option of select the text field will load/appear value in proportion to value of select, example in picture when I choose "B" in select field, the value in text filed will appear "1", so how to do it, I need example to refer, guide or demo example, Thank for read my topic.
Here is Image:
Code:
Code:
<head>
<title>Untitled Document</title>
<style type="text/css">
</style>
</head>
<body>
<center>
<br />
<form id="cv" action="" method="">
Choose Option: <select id="chedo">
<option>--Choose Value--</option>
<option>A</option>
<option>B</option>
<option>C</option>
</select>
<br />
<br />
Value: <input type="text" id="lenh" size="40"/>
<br />
<br />
<input type="submit" value="SUBMIT"/>
</form>
</center>
</body>
</html>
-
December 28th, 2013, 04:32 PM
#2
Re: How to load value to text field when choose value in select
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
-
December 28th, 2013, 04:37 PM
#3
Re: How to load value to text field when choose value in select
The solution you need is JavaScript, not PHP. First you need to do a minor update to your <select>
Code:
<select id="chedo" onchange="updateTextInput(this)">
After that, then it's a simple JavaScript function...
PHP Code:
function updateTextInput(elem) { var tmpOutput = "";
switch(elem.value) { case "A": tmpOutput = "1"; break; case "B": tmpOutput = "2"; break; case "C": tmpOutput = "3"; break; }
document.getElementById("lenh").value = tmpOutput; }
If the post was helpful...Rate it! Remember to use [code] or [php] tags.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|