For help with installation, bugs reports or feature requests, please head over to our new forums.
Genuitec Community on GitHub
- This topic has 7 replies, 3 voices, and was last updated 12 years, 11 months ago by
alonso100.
-
AuthorPosts
-
alonso100MemberHi,
what´s wrong with this code: ??
function dynamic_code(){ var htmlcode = "<script type='text/javascript'>" + "document.write('Something here')" + "</script>" $('#m1-test2-html1').html(htmlcode); }
I use it for feeding an HTML-element on the screen and all I get is a white page. If I feed the code for a table (with <table>, <thead>, <tbody>,<tr>, <td>, etc) it works fine. If I enter the code directly in the widget, then it also works.
October 7, 2012 at 11:37 am #330916
alonso100MemberSearching in the internet for a way to avoid using document.write I found that I can work with appendChild, so I created this example:
function input_field(){ var htmlcode = "<script type='text/javascript'>" + "var input1='';" + "input1 = document.createElement('input');" + "input1.setAttribute('type', 'text');" + "input1.setAttribute('size', '20');" + "input1.setAttribute('border', '0');" + "input1.setAttribute('value', 'Nombre:');" + "input1.setAttribute('id', 'field1');" + "input1.style.border = 'none';" + "document.getElementsByTagName('body').appendChild(input1);" + //"alert(document.getElementsByTagName('body'));" + "</script>" $('#m1-test2-html1').html(htmlcode); }
It works in any browser but not in MobiOne. Working with Alert I can see that input1 has been correctly created and can also get Body with “document.getElementsByTagName(‘body’)” but when I add a child to the object, then I get this error message:
TypeError: Result of expression document.getElementsByTagName(‘body’).appendChild [undefined] is not a function.
What is the problem here ?? is appendChild not supported in MobiOne ??
October 7, 2012 at 6:53 pm #330925
support-michaelKeymasterWill look into this tomorrow (Mon). My 1st thought is probably css issue or error in the code.
October 9, 2012 at 11:59 am #331014
alonso100MemberHi,
any news on this ??
October 9, 2012 at 1:37 pm #331016
support-michaelKeymasterI haven’t tried running this code as it seems flawed in someways.
0) where in the dom are you inserting this code? What type of html element is $(‘#m1-test2-html1’)? Is it the node of an hmlt widget or something else. Also you must keep in mind that MobiOne UI’s are laid out using CSS extensively.
1) why generate a script to run javascript from a javascript function?
What am I missing that you can’t just build your html string and add it directly w/o nesting it in a script?October 9, 2012 at 1:56 pm #331018
alonso100MemberThe ‘#m1-test2-html1’ is the normal HTML widget and the code in the JS function is called in the event phoneui.documentReadyHandler. I insert the code in the *_custom.js file.
I can enter the code directly in the event without need of building a JS function. I did it here for shortening the example. See that I display 2 examples and none is working correctly in the mentioned event.
October 9, 2012 at 2:59 pm #331023
support-octavioMemberHi Alonso,
The problem is with: document.getElementsByTagName(‘body’), that returns a list, so you can not add your input, instead that you could use:
document.getElementById('m1-test2-html1').appendChild(input1)
Let me know how it goes.
Q: Where are you located? I noticed that you used “Nombre” in your input.October 9, 2012 at 4:02 pm #331024
alonso100MemberHi,
that works now but tell me, is this code not supported: ??
"<script type='text/javascript'>" + "document.write('Something here')" + "</script>"
-
AuthorPosts