Link to home
Start Free TrialLog in
Avatar of Robert Granlund
Robert GranlundFlag for United States of America

asked on

jQuery From Input Update

I have a form that I would like to change the value of an input by it's name.  For some reason I'm having an issue with targeting the name:

<script>
$( 'input[name="item[0][total"]' ).val( damage_total );
</script>

<html>
<input type="text" value="296" name="item[0][total]">
</html>

Open in new window

Avatar of John Easton
John Easton
Flag of United Kingdom of Great Britain and Northern Ireland image

I'm not great at jquery - still using old fashion javascript.  But it looks like your apostrophes' are out of place.  I think your line 2 should read:
$( 'input[name="item[0][total]"' ).val( damage_total );

Open in new window

I hope it is that simple.
Avatar of Chris Stanyon
You need to escape the array brackets:

$('input[name=item\\[0\\]\\[total\\]]' ).val( damage_total );

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of Chris Stanyon
Chris Stanyon
Flag of United Kingdom of Great Britain and Northern Ireland image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi,
I guess just a simple typo - there was one closing bracket missing:
$( 'input[name="item[0][total]"]' ).val( damage_total );

Open in new window

But you should reconsider to change your element names as I doubt that brackets are allowed characters.

HTH
Rainer
Too late :-) By 16 seconds :-]
@Rainer - brackets are allowed in inputs and actually I'd strongly recommend them - they're an easy way to group form data - making the POST processing much simpler