开发者

inserting values into hidden, and database problem?

i have this jquery code, which inserst the css property into a hidden input: here goes

$('#borderleft').val($('.leftpanel').css('border-left-width',"20px"));

and my hidden input field looks like:

 <input type="hidden" id="borderleft"name="borderleft"></input>

when i try to insert this input into the database, i get the value

[object Object] 

instead of

20px

wha开发者_Python百科t is the problem, i dnt seem to understand thanks!!


The issue you're running into here is that almost all of the jQuery methods return the instance of the object itself, so you can "chain" functions together. When you call:

$('.leftpanel').css('border-left-width',"20px")

The call to css actually returns the value of $('.leftpanel'), which is of course, an object.

Now, I gather you are intending to set the value of the hidden field to '20px', you can do so by the following:

var width = '20px';
$('.leftpanel').css('border-left-width',width)
$('#borderleft').val(width);

Update

If your intention is to simply get the current border width of the element, and set the value of your hidden field, you need to omit the second parameter to css, doing so will return you the current value. Your resulting code would be:

$('#borderleft').val($('.leftpanel').css('border-left-width'));
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜