tags:

views:

41

answers:

3

Hello,

When #sw is clicked, I need alert(dc); to be triggered

<form name="sc" action="" method="">
<div class="si" id="seli" style="position:absolute; left:15px; top:200px; width:260px;">
<select>
<?  do { $k = $row_w['k']; ?>
<option value="<? echo $k1; ?>"><? echo $1k; ?></option>
<? } while ($row_kw = mysql_fetch_assoc($kw)); ?>
</select>

<input type="submit" value="save" />
</div>
<input type="hidden" id="dc" class="dct" value="5"/>
<div id="sw" style="cursor:pointer;"></div>
</form>

and the jquery code

$('#sw').bind('click',function(e) {

                                                 var x = (e.target.id);

                                                 var y = x.substr(5,1);
                                                 var dn = ($(e.target).text());
                                                 var x1 = '<div class="s" id=s'+y+' style="margin-bottom:3px; text-align:left; border-bottom:#cccccc solid thin;">'+do_nm+'</div>';

                                                 $('.si').append(x1);
                                                 $('#'+x).fadeOut('slow');

                                                 var dc1= ('#dc').val();
                                                 alert(dc);

                                                 });

Thanks Jean

A: 

I think you're almost there. I not completely sure of the question, but if you replace:

var dc1= ('#dc').val();
alert(dc);

with:

var dc = $('#dc')[0].value;
alert(dc);

You must use [0] because jQuery's $() returns a collection of items, and the collections does not have a value property, but the instance in the collection does.

Emil
Pops up as undefined
Jean
`.val()` is basically the same as `[0].value` (first will take jQuery overload, which internally requests the `value`-property)
Andreas Niedermair
A: 

Replace

var dc1= ('#dc').val();
  var dc1= ('#dc').val();
 alert(dc);

with

 alert($('#dc').val());
Kai
A: 

you've got a typo in there

var dc1= ('#dc').val();
alert(dc);

make it

var dc = $('#dc').val();
alert(dc);

also: be sure that the id is unique in your dom! otherwise you might want to work with your class:

var dc = $('.dct').val();
alert(dc);
Andreas Niedermair