PHP Web Developer.

กรกฎาคม 20, 2012

Select option display value in texbox use jquery

Filed under: Javascript & jquery — Prajak @ 1:57 pm

======= Code =======
<script src=”http://ajax.googleapis.com/ajax/libs/jquery/1.5/jquery.min.js”></script&gt;
<script>
// Define array name
var selectId = [];
var selectName = [];
var selectNameValue = [];
var selectValue = [];

// Define the Latin Alphabet
var alphabet = “ABCDEFGHIJKLMNOPQRSTUVWXYZ”;

// Nested loop to find frequencies and input them into the hashtable
var a=1;
for (d=0; d<=25; d++) {
var alphabetValue = alphabet.charAt(d)+’ : ‘+(a*5);
selectId.push(d);
selectName.push(alphabet.charAt(d));
selectNameValue.push(alphabetValue);
selectValue.push(a*5);
a++;
}

$(document).ready(function() {

// for display partnerComPercentag
$(“select#select_id”).change(function(){
$(‘#textName’).val((selectName[$(this).val()]));
$(‘#textValue’).val((selectValue[$(this).val()]));
});

});
</script>
<div>

Select :
<select id=”select_id” name=”select_id”>
<script>
for(i=0;i<selectId.length;i++){
var option = ‘<option value=”‘+selectId[i]+'”>’+selectNameValue[i]+'</option>’;
document.write(option);
}
</script>
</select>
Display select : <input type=”text” id=”textName” name=”textName”/>
Display value : <input type=”text” id=”textValue” name=”textValue”/>
</div>

======= End Code =======

ให้ความเห็น »

ยังไม่มีความเห็น

RSS feed for comments on this post. TrackBack URI

ใส่ความเห็น

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 / เปลี่ยนแปลง )

Twitter picture

You are commenting using your Twitter account. Log Out / เปลี่ยนแปลง )

Facebook photo

You are commenting using your Facebook account. Log Out / เปลี่ยนแปลง )

Google+ photo

You are commenting using your Google+ account. Log Out / เปลี่ยนแปลง )

Connecting to %s

บลอกที่ WordPress.com .

%d bloggers like this: