3
Answers

first element in comma saperated value and Jquery

Photo of albert albert

albert albert

12y
899
1
Hi everybody,

I have a list of weeks, like this:

[code]
select id="weekIdclass="validonchange="Selectedchange();name="weekId">

[code]

I can get the value with JQuery like this:

[code]
function Selectedchange() {
    $("#txtBox").val($("#weekId").val());
       
        //.attr("selected",0);
}
[/code]

But I want to have the first value: { maandag = 2-1-2012} in a textbox.

How to do that?

THX




Answers (3)

0
Photo of Pankaj  Kumar Choudhary
NA 29.8k 3.1m 9y
hello Albert first of all make your option as check
 
<option selected="selected" value="{ maandag = 2-1-2012, Dindsdag = 3-1-2012 }">1</option>
 
now use this method in jquery
 
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
$(document).ready(function () {
var values = $("#weekId option:selected").val();
$("#txtBox").val(values);
});
function Selectedchange() {
var values = $("#weekId option:selected").val();
$("#txtBox").val(values);
}
</script>
 
this method work very well for me
 
0
Photo of Seliya Hilal
NA 25 0 9y
try this.. will work for sure
 
<input type="text" id="txtBox" />
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js" type="text/javascript"></script>
<script>
function Selectedchange() {
var values = $("#weekId option:selected").val();
$("#txtBox").val(values);
}
</script>
 
0
Photo of albert albert
NA 503 0 12y
I tried, like this:

[code]
function Selectedchange() {
    $("#txtBox").val($("#weekId").val().split(","));
       
        //.attr("selected",0);
}
[/code]

but that doesnt work.
Next Recommended Forum