Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

javascript, innerHtml dosent work in ie on mac os

Status
Not open for further replies.

jsprogrammer

Programmer
Aug 30, 2005
3
0
0
US
hi
javascript, innerHtml dosent work in ie on mac os.
please help me its urgent

example, when you mouse over the text it should add a hidden field but it dosent

<html>
<head>

<script type="text/javascript">

function nameon()
{

document.getElementById('param').innerHTML = '<INPUT name=111 value=222 TYPE=hidden>';

alert( document.getElementById('param').innerHTML );

for (var i = 0; i < document.testForm.elements.length; i++)
{
alert( document.testForm.elements.name + ' = ' + document.testForm.elements.value);
}
}

</script>

</head>
<body>


<FORM name="testForm" id="testForm" METHOD=POST ACTION="">

<span id="h2text" onmouseover="nameon()">Mouse over this text!</span>

<a id="param"> </a>
</FORM>

</body>
</html>
 
innerHTML is not a DOM-compliant property, so you can't expect it to work on all browsers all the time. Suggest this instead:

Code:
var _parent = document.getElementById('param');
var _newInput = document.createElement('input');
_newInput.type = 'hidden';
_newInput.name = 'X111';
_newInput.value = '222';
_parent.appendChild(_newInput);

Also, notice I have changed the name so it begins with a letter. Names must not begin with numbers.

Hope this helps,
Dan


[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
Thanks a million BillyRayPreachersSon for replying but this doesn’t ether work.
 
- Do you actually have an element with an id of "param" on the page?

- Are you waiting for the page to fully load and parse before running the script?

If so, can you post your code, or a URL to it?

Dan



[tt]Dan's Page [blue]@[/blue] Code Couch
[/tt]
 
I am sorry I missed you yesterday

Here is the code you could test it if you have a Mac os.
And your second question I don’t understand.
Thank for helping me

<html>
<head>

<script type="text/javascript">

function nameon()
{
var _parent = document.getElementById('param');
var _newInput = document.createElement('input');
_newInput.type = 'hidden';
_newInput.name = 'myName';
_newInput.value = 'myValue';
_parent.appendChild(_newInput);

alert( document.getElementById('param').innerHTML );

for (var i = 0; i < document.testForm.elements.length; i++)
{
alert( document.testForm.elements.name + ' = ' + document.testForm.elements.value);
}
}

</script>

</head>
<body>

<FORM name="testForm" id="testForm">

<span id="h2text" onmouseover="nameon()">Mouse over this text!</span>

<a id="param"> </a>
</FORM>

</body>
</html>
 
Unless it's absolutely necessary to use IE on Mac, you might consider an alternative browser. IE isn't supported anymore and, when it was, it was still a pretty crappy browser compared to its Windows counterpart. Just my 2 cents, however.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top