Submit Your Article Webforumz RegistrationAnnouncements Contact Webforumz StaffContact
Home Resources Blogs Meet the Team Contact Register
 

Go Back   WebForumz.com > The Code > JavaScript

Reply
 
LinkBack Thread Tools
Old October 15th, 2008, 08:52 AM   #1
New Member
 

Join Date: Jul 2006
Location: London
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c_martini is on a distinguished road
Checkbox to affect hidden field value

I have a form with a checkbox. I also have a hidden field in that form with a different name. I need to have the hidden field's value populated when the checkbox is checked. If the checkbox is then unchecked, the value of the hidden field should also be reset back to nothing.

Code:
<input type="checkbox" name="user_can_use_data" id="user_can_use_data" value=""  />

<input type="hidden" name="supplier_can_use_data" id="supplier_can_use_data" value="" />
I know a very simple bit of javascript should do the trick, but have not been able to figure it out...

Any ideas?
c_martini is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 15th, 2008, 10:33 PM   #2
Most Reputable Member
 

Join Date: Feb 2008
Location: In My Own Little World
Age: 16
Posts: 1,345
Blog Entries: 9
Thanks: 2
Thanked 45 Times in 45 Posts
Rep Altering Power: 0 CloudedVision is on a distinguished road
Re: Checkbox to affect hidden field value

You know you don't need javascript for that:

Code:
<input type="checkbox" name="awesome" value="shtuff">
That will send "shtuff" when checked and nothing when not checked.
__________________
Theron Luhn
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 16th, 2008, 04:42 AM   #3
New Member
 

Join Date: Jul 2006
Location: London
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c_martini is on a distinguished road
Question Re: Checkbox to affect hidden field value

Quote:
Originally Posted by CloudedVision View Post
You know you don't need javascript for that:

Code:
<input type="checkbox" name="awesome" value="shtuff">
That will send "shtuff" when checked and nothing when not checked.
Hmm. Think perhaps I wasn't clear about what I need. The hidden field is for a separate bit of info in the form. It needs to be there to submit a value for its name. The checkbox not only handles its own value, but should fill a checkbox value for the hidden field. Or unless a checkbox can be made to submit values for two different variables....



Does this make more sense? I know its something commonly done in forms but I am drawing a blank this week for some reason. Think I am working too much
c_martini is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 16th, 2008, 05:06 PM   #4
Most Reputable Member
 

Join Date: Feb 2008
Location: In My Own Little World
Age: 16
Posts: 1,345
Blog Entries: 9
Thanks: 2
Thanked 45 Times in 45 Posts
Rep Altering Power: 0 CloudedVision is on a distinguished road
Re: Checkbox to affect hidden field value

I don't see why you need a seperate field for this. couldn't you do that server side?

Code:
if(isset($_POST['checkbox'])
$_POST['checkbox2'] = "Hello!"
You should try to steer away from something that only works with javascript - many people have javascript disabled. (Or sometimes if there's any javascript errors a browser will halt all javascript processes on the site. I believe IE6 does this.... although i may be wrong, ive given up on IE6 all together lol)
__________________
Theron Luhn
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 17th, 2008, 04:31 AM   #5
New Member
 

Join Date: Jul 2006
Location: London
Posts: 34
Thanks: 0
Thanked 0 Times in 0 Posts
Rep Altering Power: 0 c_martini is on a distinguished road
Question Re: Checkbox to affect hidden field value

Quote:
Originally Posted by CloudedVision View Post
I don't see why you need a seperate field for this. couldn't you do that server side?

Code:
if(isset($_POST['checkbox'])
$_POST['checkbox2'] = "Hello!"
You should try to steer away from something that only works with javascript - many people have javascript disabled. (Or sometimes if there's any javascript errors a browser will halt all javascript processes on the site. I believe IE6 does this.... although i may be wrong, ive given up on IE6 all together lol)
We don't use php on the servers in question. The language is proprietary. For this bit of functionality I don't have the option of making this server-side. Also, this site is for a chain of music stores and runs on thin clients connected to a main server via Citrix running Windows and IE6. The forms within the transaction processes have to be kept very simple so that staff in store can take customer orders fast and efficiently. The javascript functions are simply to make the whole process easier for staff to fill in the forms in front of customers.

Couldn't the one checkbox be made to set the same value for two, both itself and a second hidden field?

Last edited by c_martini; October 17th, 2008 at 04:36 AM.. Reason: spelling
c_martini is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Old October 17th, 2008, 05:26 PM   #6
Most Reputable Member
 

Join Date: Feb 2008
Location: In My Own Little World
Age: 16
Posts: 1,345
Blog Entries: 9
Thanks: 2
Thanked 45 Times in 45 Posts
Rep Altering Power: 0 CloudedVision is on a distinguished road
Re: Checkbox to affect hidden field value

If use must use javascript, check out javascript checkboxes. http://homepage.ntlworld.com/kayseycarvey/jss3p8.html
__________________
Theron Luhn
CloudedVision is offline  
Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!Spurl this Post!Reddit! Wong this Post!
Reply With Quote
Reply

Bookmarks


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Similar Threads
Thread Thread Starter Forum Replies Last Post
Need javascript to set input field value field jdadwilson JavaScript 3 May 9th, 2007 12:47 AM
I need to make a checkbox a required field vandiermen JavaScript 3 April 7th, 2007 03:13 PM
validate text field to db field jtesolin Classic ASP 1 July 18th, 2006 01:48 PM
Javascript Hidden field problem... Rudie JavaScript 14 June 20th, 2006 06:06 PM
Glow affect lesleindotcom Graphic Specifics 14 April 29th, 2006 03:37 PM


Search Engine Optimization by vBSEO 3.2.0 RC8