Jump to content

onclick function not working in IE but works in FireFox


NFD

Recommended Posts

This originally started here:

http://www.phpfreaks.com/forums/index.php/topic,204898.0.html

and has progressed now into purely a javascript problem I need help with.

 

I am having one last issue with getting a field update working correctly.

i.e.

When I selection an option from a drop down list, I need it to fill out details in a form from a php array.

 

In firefox, this works perfectly.

In IE however, it doesn't appear to do anything.

 

Here is a small snippet of the javascript I am using:

<script type="text/javascript">
function data_copy_address_{VAL_AA_SID}()
{

document.getElementById('title').value = "{VAL_AA_TITLE}";
document.getElementById('firstName').value = "{VAL_AA_FIRST_NAME}";
document.getElementById('lastName').value = "{VAL_AA_LAST_NAME}";
document.getElementById('add_1').value = "{VAL_AA_ADDRESS_1}";
document.getElementById('add_2').value = "{VAL_AA_ADDRESS_2}";
document.getElementById('town').value = "{VAL_AA_CITY}";
document.getElementById('county').value = "{VAL_AA_STATE}";
document.getElementById('postcode').value = "{VAL_AA_ZIP}";
document.getElementById('country').value = "{VAL_AA_COUNTRY_NAME}";

}
</script>

 

Here is an example of a form field to be filled:

<td><input name="delInf[title]" type="text" class="textbox" id="title" value="{VAL_DEL_TITLE}" size="7" maxlength="30" />

 

And here is the select itself:

<select  name="addresses" id="addresses" class="textbox">
<option value="0">Please select...</option>
<!-- BEGIN: addresses_loop -->
<option onclick="data_copy_address_{VAL_AA_SID}()" value="{VAL_AA_SID}">{VAL_AA_TITLE} {VAL_AA_FIRST_NAME} {VAL_AA_LAST_NAME},{VAL_AA_ADDRESS_1} {VAL_AA_ADDRESS_2} {VAL_AA_CITY}, {VAL_AA_STATE}, {VAL_AA_ZIP}, {VAL_AA_COUNTRY_NAME}</option>
<!-- END: addresses_loop -->
<option onclick="data_copy_address_clear()" value="clear">Clear above and manually enter address</option>
<option onclick="data_copy_address_default()" value="default">Deliver to invoice address</option>
</select>

 

I have since learned that IE wont process the onclicks assigned to an option and therefore populate the fields.

 

If I use something like:

<select  name="addresses" id="addresses" class="textbox" onchange="data_copy_address_{VAL_AA_SID}()">

that then inserts the data from the last entry in the array only.

 

Would it be possible to have either a dummy kind of call there that then forces IE to use the onclicks?

 

Or would it be possible to have something like:

onchange="data_copy_address_()"

on the select and then have the ID of the option clicked passed to the JS itself?

 

i.e.

If option id '2' (via {VAL_AA_SID}) is selected it then runs:

function data_copy_address_({VAL_AA_SID})
{

document.getElementById('title').value = "{VAL_AA_TITLE}";
document.getElementById('firstName').value = "{VAL_AA_FIRST_NAME}";
document.getElementById('lastName').value = "{VAL_AA_LAST_NAME}";
document.getElementById('add_1').value = "{VAL_AA_ADDRESS_1}";
document.getElementById('add_2').value = "{VAL_AA_ADDRESS_2}";
document.getElementById('town').value = "{VAL_AA_CITY}";
document.getElementById('county').value = "{VAL_AA_STATE}";
document.getElementById('postcode').value = "{VAL_AA_ZIP}";
document.getElementById('country').value = "{VAL_AA_COUNTRY_NAME}";

}

 

Or something along those lines?

Link to comment
Share on other sites

I'm assuming that those constants are actually used as variables somehow (which really confuses me).

Since I have no idea what you are trying to do, I will give you an example of what I think is something similar:

<script>
function data_copy_address($address)
{
   document.getElementById('title').value = $address;
}
</script>

<select onChange="data_copy_address(this.value)">
<option value="address">Option 1</option>
</select>

 

With that onChange event, the value of the select (this) will be the value of whatever option is selected.

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.