aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes Help setting field value from checkbox value using jQuery Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "Help setting field value from checkbox value using jQuery" Watch "Help setting field value from checkbox value using jQuery" New topic
Author

Help setting field value from checkbox value using jQuery

Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
So with my code I'm looking to take a value out of a checkbox and put it into a text field. The code is in JSFIDDLE. See the link below. I use the latest JQuery as well.

http://jsfiddle.net/ddemott/MUU3z/

The problem I'm having is I can't seem to get the checkbox value go into the input field. It pops up in the alert but won't go into the field. I'm obviously missing something. Here's the code snippet.



Here's the code. As you can see I look to see how many checkboxes were checked. If there was only ONE checkbox checked then I popup up the value in an alert. But when I try to put x into the field of 'returnValue' it doesn't change the input field. If you go to jsfiddle you'll see this code execute when you click a single room.

Below is all of the code (without the script tags)



and the HTML



By failing to prepare, you are preparing to fail.<br />Benjamin Franklin (1706 - 1790)
Eric Pascarello
author
Rancher

Joined: Nov 08, 2001
Posts: 15376
    
    6
Your code is setting the value correctly, you just have too much logic going in multiple places that resets the value. [also use console.log() to debug and not alerts]

Eric
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60991
    
  65

I agree with Eric -- the code is not logically organized and is stepping all over itself. I'd actually advise deleting the whole thing, taking a deep breath, figure out what you're actually trying to accomplish, and try again.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Dale DeMott
Ranch Hand

Joined: Nov 02, 2000
Posts: 515
Once I cleaned it up and got my head around the logic it fell together much nicer. All is working now.

See code in JSFiddle.

http://jsfiddle.net/ddemott/5k396/38/
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Help setting field value from checkbox value using jQuery