Current location: Hot Scripts Forums » General Web Coding » HTML/XHTML/XML » onClick event - solution for Safari?


onClick event - solution for Safari?

Reply
  #1 (permalink)  
Old 04-14-09, 01:58 AM
xenia_jazz xenia_jazz is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
onClick event - solution for Safari?

I'm trying to get something to work for some text fields that transfer data from a number of fields into others if a checkbox or button is clicked. I initially had a button tag, but a couple of browsers would actually submit my form, so I changed it to a checkbox. Unfortunately, Safari does not assign the values to the respective text boxes. Anybody know a solution for this?


HTML Code:
<input type="checkbox" onClick="document.getElementById('bfname').value=document.getElementById('name1').value,
		document.getElementById('blname').value=document.getElementById('name2').value,
		document.getElementById('badd1').value=document.getElementById('add1').value,
		document.getElementById('bcity').value=document.getElementById('ucity').value,
		document.getElementById('bstate').value=document.getElementById('ustate').value,
		document.getElementById('bzip').value=document.getElementById('uzip').value">
Thanks in advance
Reply With Quote
  #2 (permalink)  
Old 04-14-09, 07:20 PM
dgreenhouse's Avatar
dgreenhouse dgreenhouse is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: San Francisco
Posts: 457
Thanks: 0
Thanked 3 Times in 3 Posts
You need to separate each statement with a semicolon ";" not a comma ",".

Code:
<input type="text" id="bfname"><br />
<input type="text" id="name1"><br />
<input type="text" id="blname"><br />
<input type="text" id="name2"><br />
<input type="text" id="badd1"><br />
<input type="text" id="add1"><br />
<input type="text" id="bcity"><br />
<input type="text" id="ucity"><br />
<input type="text" id="bstate"><br />
<input type="text" id="ustate"><br />
<input type="text" id="bzip"><br />
<input type="text" id="uzip"><br />

<input type="checkbox" onClick="document.getElementById('bfname').value=document.getElementById('name1').value;
		document.getElementById('blname').value=document.getElementById('name2').value;
		document.getElementById('badd1').value=document.getElementById('add1').value;
		document.getElementById('bcity').value=document.getElementById('ucity').value;
		document.getElementById('bstate').value=document.getElementById('ustate').value;
		document.getElementById('bzip').value=document.getElementById('uzip').value">
But that's a lot of assignments to place in the UI - better to put them in a script file or in script tag in the page.

i.e.

Code:
<input type="checkbox" onClick="doAssignments()">
Reply With Quote
  #3 (permalink)  
Old 04-14-09, 11:35 PM
xenia_jazz xenia_jazz is offline
Newbie Coder
 
Join Date: Jan 2009
Posts: 10
Thanks: 0
Thanked 0 Times in 0 Posts
I changed the commas to semicolons on the onclick event, but still no change while testing in Safari.

Do you know what event for what input types would work in Safari? Or if the above code should be working? I'm on PC using Safari 3.2.2
Reply With Quote
  #4 (permalink)  
Old 04-16-09, 12:16 PM
dgreenhouse's Avatar
dgreenhouse dgreenhouse is offline
Aspiring Coder
 
Join Date: Mar 2009
Location: San Francisco
Posts: 457
Thanks: 0
Thanked 3 Times in 3 Posts
I ran that in Safari on a PC and it works.

As far as I know, all modern browsers implement getElementById().

Something's wrong on the page you're putting it on.
Reply With Quote
  #5 (permalink)  
Old 04-17-09, 04:25 AM
harish harish is offline
Newbie Coder
 
Join Date: Apr 2009
Posts: 52
Thanks: 0
Thanked 0 Times in 0 Posts
I think you should use that code for creating check box

Code:
<input type="checkbox" onClick="doAssignments()">
Reply With Quote
Reply

Bookmarks


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

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 Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On

Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Onclick event of a button not working phathutshedzo ASP.NET 4 12-06-06 05:28 AM
Onclick event of a Datagrid's buttonColumn phathutshedzo ASP.NET 11 11-16-06 11:00 AM
Some Onclick event help. Killswitch JavaScript 0 07-07-05 04:44 PM
Javascipt onClick event Tonyk86 JavaScript 1 02-22-05 02:44 AM


All times are GMT -5. The time now is 09:05 PM.
vBulletin® Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.