Forum Moderators: open

Message Too Old, No Replies

onclick="doIt()" works on PC but not mac?

onclick="doIt()" works on PC but not mac?

         

stroudtx

7:09 am on May 7, 2006 (gmt 0)

10+ Year Member



I'm using a little javascript to move fields from one form where the selections are made to another where it submits to a registry shopping cart. There are 2 which requires the two forms and this javascript code.

It works great on the PC and I was about to go live. I tried it on my mac and it didn't work.

Any suggestions or clue? I have the same exact code on a page with customer data and it moves the billing address to shipping with an onclick even on a check box. The only difference here is it a image button.

<script type="text/javascript">
function doIt() {
document.getElementById('size2').value = document.getElementById('size').value;
document.getElementById('opt1').value = document.getElementById('Option1').value;
document.getElementById('opt2').value = document.getElementById('Option2').value;
document.getElementById('opt3').value = document.getElementById('Option3').value;
document.getElementById('persregistry').value = document.getElementById('Presonalize').value;
}
</script>

<input type="image" src="Images/addregistrybutton.gif" border="0" value="Add To Cart" name="registry_1_ATC" onclick="doIt();" alt="Add to Registry" />

kaled

10:52 am on May 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Assuming you have a select-one object, I believe you need to use the selectedIndex property to access its value.

The following is untested but based on working code.

function optionsGetValue(optionsId){
var options = document.getElementById(optionsId); if (!options) then return;
var i = options.selectedIndex;
return options.options[i].text;
}

Kaled.

stroudtx

8:58 pm on May 7, 2006 (gmt 0)

10+ Year Member



Thanks - I got some progress made, but still a huge way to go.....Here's a litte better description.

I've got a slew of javascript problems revolving around IE, Safari, etc. 3 AM last night. Some forward progress, but not much else. Really could use some advice here.

I built a registry system that uses a separate shopping cart. This creates a second form on each product page.

Each product can have up to 3 drop down values (labels & cost) and there is a field for personalization.

I have successfully found a way to get the labels chosen on the drop downs, but can't get the actual values or the personalization. Here is my doIt statement.. This is supposed to get the size label (it does), then the options value (it does not), and the personalization text field (it doesn't)

Here's code so far...

<script language="Text/JavaScript"> function doIt() {

document.getElementById('size2').value = document.getElementById('size').options[document.getElementById('size').selectedIndex].value;

document.getElementById('opt1').value = document.getElementById('Option1').options[document.getElementById('Option1').selectedtext].value;

document.getElementById('opt2').value = document.getElementById('Option2').options[document.getElementById('Option2').selectedIndex].value;

document.getElementById('opt3').value = document.getElementById('Option3').options[document.getElementById('Option3').selectedIndex].value;

document.getElementById('persregistry').value = document.getElementById('Presonalize').value;
}
</script>

RonPK

10:12 pm on May 7, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



<script language="Text/JavaScript">

The language attribute is deprecated in HTML 4.01, and language="Text/JavaScript" would not have been a useful value anyway. Your previous code (type="text/javascript") was correct.

Also, maybe you should make sure that the script is executed before the form is submitted:
* use

onclick="return doIt();"

* have the function return true after doing its things: add
return true;
as the last line of the function.

stroudtx

6:51 am on May 8, 2006 (gmt 0)

10+ Year Member



Thanks - I fixed these and found some other issues. It's all up and working - Somewhat tested. I'm advertising in Google for Baby Gift Registry. I hope my hard work pays off :)

This site is invalable for my sucess so far.

Mike

stroudtx

4:20 pm on May 8, 2006 (gmt 0)

10+ Year Member



thanks, I got it working.