vForums Support > Programming & Coding :: Code Requests & Support :: > Code not working....

Code not working.... - Posted By Nick (nickb) on 9th Sep 08 at 6:05pm
I have added extra lines but it seems as its not working! Whats wrong?

Code:
 
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. /* Predefined Posting Template/Form
  5.     Created by Ross of vForums
  6.     http://virtualforums.co.uk
  7.     Please do not repost outside of
  8.     vForums support without permission */
  9.  
  10. var _title = 'YGO: Duelists Realm Character Creation Form';
  11.  
  12. var _description = '';
  13.  
  14. var _fields = new Array(); var _f = 0;
  15.     _fields[_f++] = new Array('input', 'Character name', ['size', 40, 'maxLength', 50], '', 'What is the name of your character?', false);
  16.     _fields[_f++] = new Array('input', 'Age', ['size', 40, 'maxLength', 50], '', 'What is your characters age?', false);
  17.     _fields[_f++] = new Array('input', 'Gender', ['size', 40, 'maxLength', 50], '', 'What is the gender of your character?', false);
  18.     _fields[_f++] = new Array('input', 'Species', ['size', 40, 'maxLength', 250], '', 'What is your characters Species?.', false);
  19.     _fields[_f++] = new Array('input', 'Good/Evil/Neutral', ['cols', 40, 'rows', 3], '', 'Please tell us if you are good, evil, or neutral.', false);
  20.     _fields[_f++] = new Array('textarea', 'Appearance', ['size', 40, 'maxLength', 350], '', 'Please give a description of your characters appearence.', false);
  21.     _fields[_f++] = new Array('textarea', 'Personality', ['cols', 40, 'rows', 4], '', 'What is your character personality like?.', false);
  22.     _fields[_f++] = new Array('textarea', 'History', ['size', 40, 'maxLength', 350], '', 'Please tell us you characters history.', false);
  23.     _fields[_f++] = new Array('textarea', 'Cards', ['size', 40, 'maxLength', 250], '', 'Please list your cards', false);
  24.     _fields[_f++] = new Array('textarea', 'Hobbies', ['size', 40, 'maxLength', 250], '', 'What are your characters hobbies?', false);
  25.     _fields[_f++] = new Array('textarea', 'Jobs', ['size', 40, 'maxLength', 250], '', 'What kind of job does your character do? IE: Duelist, Card seller, unemployed, etc.', false);
  26.     _fields[_f++] = new Array('textarea', 'Example RP', ['size', 40, 'maxLength', 0], '', 'Follow the RP below', false);
  27.     _fields[_f++] = new Array('input', 'Counter', ['size', 40, 'maxLength', 50], '', 'This Field is for when it is your turn after your opponents, this will be for counter attacks such as effect of spells, traps, and effect monsters', false);
  28.     _fields[_f++] = new Array('input', 'Comments', ['size', 40, 'maxLength', 50], '', 'Pretend you are dueling someone and make a comment about their play', false);
  29.     _fields[_f++] = new Array('input', 'Draw Phase', ['size', 40, 'maxLength', 50], '', 'This is your Draw Phase.', false);
  30.     _fields[_f++] = new Array('input', 'Standby Phase', ['size', 40, 'maxLength', 50], '', 'This is your standby phase to look at your hand.', false);
  31.     _fields[_f++] = new Array('input', 'Main Phase 1', ['size', 40, 'maxLength', 50], '', 'This is your main phase 1 to place a monster or trap/spell card', false);
  32.     _fields[_f++] = new Array('input', 'Battle Phase', ['size', 40, 'maxLength', 50], '', 'This is the phase you attack your opponent's monsters or directly to LP.', false);
  33.     _fields[_f++] = new Array('input', 'Main Phase 2', ['size', 40, 'maxLength', 50], '', 'This phase 2 is for laying down extra cards I.E. Traps or Spells.', false);
  34.     _fields[_f++] = new Array('input', 'End Phase', ['size', 40, 'maxLength', 50], '', 'This is the end phase nothing you can do here only by saying "done".', false);
  35.  
  36.  
  37. var _widths = ['100%', '20%', '40%', '40%'];
  38.  
  39. var _posting_form = {
  40.  
  41.     errors: new Array(),
  42.  
  43.     init: function() {
  44.         this.create_form();
  45.     },
  46.     
  47.     create_form: function() {
  48.         // Create new post layout
  49.         var _holder = document.createElement('table');
  50.         _holder.setAttribute('className', 'border');
  51.         _holder.setAttribute('class', 'border');
  52.         _holder.setAttribute('cellSpacing','1');
  53.         _holder.setAttribute('cellPadding', '4');
  54.         _holder.setAttribute('align', 'center');
  55.         _holder.setAttribute('width', _widths[0]);
  56.         _holder.setAttribute('id', 'post_form_holder');
  57.         _holder.appendChild(document.createElement('tbody'));
  58.         _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') );
  59.         _holder.firstChild.lastChild.lastChild.className = 'title1';
  60.         _holder.firstChild.lastChild.lastChild.colSpan = '3';
  61.         _holder.firstChild.lastChild.lastChild.lastChild.size = '2';
  62.         _holder.firstChild.lastChild.lastChild.lastChild.appendChild(document.createTextNode(_title));
  63.         if(_description) {
  64.             _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') );
  65.             _holder.firstChild.lastChild.lastChild.setAttribute('className', 'window1');
  66.             _holder.firstChild.lastChild.lastChild.setAttribute('class', 'window1');
  67.             _holder.firstChild.lastChild.lastChild.setAttribute('colSpan', '3');
  68.             _holder.firstChild.lastChild.lastChild.lastChild.setAttribute('size', '2');
  69.             _holder.firstChild.lastChild.lastChild.lastChild.innerHTML = _description;
  70.         }
  71.         
  72.         for(_f=0; _f<_fields.length; _f++) {
  73.             switch(_fields[_f][0]) {
  74.                 case 'textarea' :
  75.                     var _tmp = document.createElement('textarea');
  76.                 break;
  77.                 
  78.                 case 'select' :
  79.                     var _tmp = document.createElement('select');
  80.                     for(_o=0; _o<_fields[_f][3].length; _o++) {
  81.                         _tmp.options[_o] = new Option(_fields[_f][3][_o], _fields[_f][3][_o]);
  82.                     }
  83.                 break;
  84.                 
  85.                 default :
  86.                     var _tmp = document.createElement('input');
  87.                     _tmp.type = 'text';
  88.                     if("undefined" != typeof _fields[_f][3] && _fields[_f][3] != "")
  89.                         _tmp.setAttribute('value', _fields[_f][3]);
  90.                 break;
  91.             }
  92.             _tmp.setAttribute('id', _f);
  93.             if("undefined" != typeof _fields[_f][2] && _fields[_f][2].length > 0) {
  94.                 for(_a=0; _a<_fields[_f][2].length; _a++) {
  95.                     _tmp.setAttribute(_fields[_f][2][_a++], _fields[_f][2][_a]);
  96.                 }
  97.             }
  98.             var _class = 'window' + ((_f % 2 == 0)? '2' : '1');
  99.             var _row = document.createElement('tr');
  100.             _row.appendChild(document.createElement('td'));
  101.             _row.lastChild.setAttribute('class', _class);
  102.             _row.lastChild.setAttribute('className', _class);
  103.             _row.lastChild.setAttribute('vAlign', 'top');
  104.             _row.lastChild.setAttribute('width', _widths[1]);
  105.             _row.lastChild.appendChild(document.createElement('font'));
  106.             _row.lastChild.lastChild.setAttribute('size', '2');
  107.             _row.lastChild.lastChild.style.fontWeight = 'bold';
  108.             _row.lastChild.lastChild.appendChild(document.createTextNode(_fields[_f][1] + ':'));
  109.             _row.appendChild(document.createElement('td'));
  110.             _row.lastChild.setAttribute('class', _class);
  111.             _row.lastChild.setAttribute('className', _class);
  112.             _row.lastChild.setAttribute('width', _widths[2]);
  113.             _row.lastChild.appendChild(document.createElement('font'));
  114.             _row.lastChild.lastChild.setAttribute('size', '2');
  115.             _row.lastChild.lastChild.appendChild(_tmp);
  116.             _row.appendChild(document.createElement('td'));
  117.             _row.lastChild.setAttribute('class', _class);
  118.             _row.lastChild.setAttribute('className', _class);
  119.             _row.lastChild.setAttribute('vAlign', 'top');
  120.             _row.lastChild.setAttribute('width', _widths[3]);
  121.             _row.lastChild.appendChild(document.createElement('font'));
  122.             _row.lastChild.lastChild.size = '1';
  123.             _row.lastChild.lastChild.appendChild(document.createTextNode(_fields[_f][4]));
  124.             _holder.firstChild.appendChild(_row);
  125.         }
  126.         var _submit = document.createElement('tr');
  127.         _submit.appendChild(document.createElement('td'));
  128.         _submit.lastChild.setAttribute('class', 'window' + (((_f+1) % 2 == 0)? '1' : '2'));
  129.         _submit.lastChild.setAttribute('className', 'window' + (((_f+1) % 2 == 0)? '1' : '2'));
  130.         _submit.lastChild.setAttribute('align', 'center');
  131.         _submit.lastChild.setAttribute('colSpan', 3);
  132.         var _button = document.createElement('input');
  133.         _button.setAttribute('type', 'button');
  134.         _button.setAttribute('value', 'Post Message');
  135.         _button.onclick = function() { _posting_form.post_it(); };
  136.         _submit.lastChild.appendChild(_button);
  137.         _holder.firstChild.appendChild(_submit);
  138.         document.post_form.style.display = 'none';
  139.         document.post_form.parentNode.insertBefore(_holder,  document.post_form);
  140.     },
  141.     
  142.     post_it: function() {
  143.         // create message and attempt to post it
  144.         this.errors = new Array();
  145.         document.post_form.message.value = document.post_form.subject.value = '';
  146.         var _sub = document.getElementById('0').value;
  147.         _fields[0][5] = true;
  148.         document.post_form.subject.value    = _sub;
  149.         for(_f=0; _f<_fields.length; _f++) {
  150.             if(document.getElementById(_f)) {
  151.                 _value = document.getElementById(_f).value;
  152.                 if(!_value || _value.match(/^s*$/)) {
  153.                     if(_f > 0 && _fields[_f][5])
  154.                         this.show_error('You have left the ' + _fields[_f][1] + ' option empty. This is a required field and as such must contain a value.');
  155.                     else
  156.                         _value = '[i]None[/i]';
  157.                 }
  158.                 document.post_form.message.value += '[b]' + _fields[_f][1] + ':[/b] ' + _value + '\n\n';
  159.             }
  160.         }
  161.         if(this.errors.length == 0)
  162.             document.post_form.post.click();
  163.         else
  164.             this.show_error();
  165.     },
  166.     
  167.     show_error: function() {
  168.         if("undefined" != typeof arguments[0] && arguments[0]) {
  169.             this.errors.push(arguments[0]);
  170.         } else {
  171.             // Show Errors
  172.             if(document.getElementById('status_holder')) {
  173.                 document.getElementById('status_holder_title').innerHTML = "An Error Has Occured";
  174.                 document.getElementById('status_holder_message').innerHTML = this.errors.join("<br />");
  175.                 document.getElementById('status_holder').style.display = 'block';
  176.             }
  177.         }
  178.     }
  179. }
  180.  
  181.  
  182.  
  183. if(document.post_form && location.href.match(/action\/post\/?$/) && vf_username != 'Guest') {
  184.     _posting_form.init();
  185. }
  186. //-->
  187. </script>
 





Re: Code not working.... - Posted By Nick (nickb) on 9th Sep 08 at 6:15pm
Sorry for double post, tried to edit my first post and it said the post was to long. {Unsure}

This is not working either:

Code:
 
  1. <script type="text/javascript">
  2. <!--
  3.  
  4. /* Predefined Posting Template/Form
  5.     Created by Ross of vForums
  6.     http://virtualforums.co.uk
  7.     Please do not repost outside of
  8.     vForums support without permission */
  9.  
  10. var _title = 'YGO: Duelists Realm Character Creation Form';
  11.  
  12. var _description = '';
  13.  
  14. var _fields = new Array(); var _f = 0;
  15.  
  16. var _fields = new Array(); var _f = 0;
  17.        _fields[_f++] = new Array('input', 'Counter', ['size', 40, 'maxLength', 50], '', 'This Field is for when it is your turn after your opponents. <br /> This will be for counter attacks such as effect of spells traps and effect monsters.', false);
  18.        _fields[_f++] = new Array('input', 'Comments', ['size', 40, 'maxLength', 50], '', 'You will comment your opponents play here.', false);
  19.        _fields[_f++] = new Array('input', 'Draw Phase', ['size', 40, 'maxLength', 50], '', 'This is your Draw Phase.', false);
  20.        _fields[_f++] = new Array('input', 'Standby Phase', ['size', 40, 'maxLength', 50], '', 'This is your standby phase to look at your hand.', false);
  21.        _fields[_f++] = new Array('input', 'Main Phase 1', ['size', 40, 'maxLength', 50], '', 'This is your main phase 1 to place a monster or trap/spell card', false);
  22.        _fields[_f++] = new Array('input', 'Battle Phase', ['size', 40, 'maxLength', 50], '', 'This is the phase you attack your opponent's monsters or directly to LP.', false);
  23.        _fields[_f++] = new Array('input', 'Main Phase 2', ['size', 40, 'maxLength', 50], '', 'This phase 2 is for laying down extra cards such as Traps or Spells.', false);
  24.        _fields[_f++] = new Array('input', 'End Phase', ['size', 40, 'maxLength', 50], '', 'This is the end phase nothing you can do here only by saying done.', false);
  25.  
  26.  
  27.  
  28. var _widths = ['100%', '20%', '40%', '40%'];
  29.  
  30. var _posting_form = {
  31.  
  32.     errors: new Array(),
  33.  
  34.     init: function() {
  35.         this.create_form();
  36.     },
  37.     
  38.     create_form: function() {
  39.         // Create new post layout
  40.         var _holder = document.createElement('table');
  41.         _holder.setAttribute('className', 'border');
  42.         _holder.setAttribute('class', 'border');
  43.         _holder.setAttribute('cellSpacing','1');
  44.         _holder.setAttribute('cellPadding', '4');
  45.         _holder.setAttribute('align', 'center');
  46.         _holder.setAttribute('width', _widths[0]);
  47.         _holder.setAttribute('id', 'post_form_holder');
  48.         _holder.appendChild(document.createElement('tbody'));
  49.         _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') );
  50.         _holder.firstChild.lastChild.lastChild.className = 'title1';
  51.         _holder.firstChild.lastChild.lastChild.colSpan = '3';
  52.         _holder.firstChild.lastChild.lastChild.lastChild.size = '2';
  53.         _holder.firstChild.lastChild.lastChild.lastChild.appendChild(document.createTextNode(_title));
  54.         if(_description) {
  55.             _holder.firstChild.appendChild( document.createElement('tr') ).appendChild( document.createElement('td') ).appendChild( document.createElement('font') );
  56.             _holder.firstChild.lastChild.lastChild.setAttribute('className', 'window1');
  57.             _holder.firstChild.lastChild.lastChild.setAttribute('class', 'window1');
  58.             _holder.firstChild.lastChild.lastChild.setAttribute('colSpan', '3');
  59.             _holder.firstChild.lastChild.lastChild.lastChild.setAttribute('size', '2');
  60.             _holder.firstChild.lastChild.lastChild.lastChild.innerHTML = _description;
  61.         }
  62.         
  63.         for(_f=0; _f<_fields.length; _f++) {
  64.             switch(_fields[_f][0]) {
  65.                 case 'textarea' :
  66.                     var _tmp = document.createElement('textarea');
  67.                 break;
  68.                 
  69.                 case 'select' :
  70.                     var _tmp = document.createElement('select');
  71.                     for(_o=0; _o<_fields[_f][3].length; _o++) {
  72.                         _tmp.options[_o] = new Option(_fields[_f][3][_o], _fields[_f][3][_o]);
  73.                     }
  74.                 break;
  75.                 
  76.                 default :
  77.                     var _tmp = document.createElement('input');
  78.                     _tmp.type = 'text';
  79.                     if("undefined" != typeof _fields[_f][3] && _fields[_f][3] != "")
  80.                         _tmp.setAttribute('value', _fields[_f][3]);
  81.                 break;
  82.             }
  83.             _tmp.setAttribute('id', _f);
  84.             if("undefined" != typeof _fields[_f][2] && _fields[_f][2].length > 0) {
  85.                 for(_a=0; _a<_fields[_f][2].length; _a++) {
  86.                     _tmp.setAttribute(_fields[_f][2][_a++], _fields[_f][2][_a]);
  87.                 }
  88.             }
  89.             var _class = 'window' + ((_f % 2 == 0)? '2' : '1');
  90.             var _row = document.createElement('tr');
  91.             _row.appendChild(document.createElement('td'));
  92.             _row.lastChild.setAttribute('class', _class);
  93.             _row.lastChild.setAttribute('className', _class);
  94.             _row.lastChild.setAttribute('vAlign', 'top');
  95.             _row.lastChild.setAttribute('width', _widths[1]);
  96.             _row.lastChild.appendChild(document.createElement('font'));
  97.             _row.lastChild.lastChild.setAttribute('size', '2');
  98.             _row.lastChild.lastChild.style.fontWeight = 'bold';
  99.             _row.lastChild.lastChild.appendChild(document.createTextNode(_fields[_f][1] + ':'));
  100.             _row.appendChild(document.createElement('td'));
  101.             _row.lastChild.setAttribute('class', _class);
  102.             _row.lastChild.setAttribute('className', _class);
  103.             _row.lastChild.setAttribute('width', _widths[2]);
  104.             _row.lastChild.appendChild(document.createElement('font'));
  105.             _row.lastChild.lastChild.setAttribute('size', '2');
  106.             _row.lastChild.lastChild.appendChild(_tmp);
  107.             _row.appendChild(document.createElement('td'));
  108.             _row.lastChild.setAttribute('class', _class);
  109.             _row.lastChild.setAttribute('className', _class);
  110.             _row.lastChild.setAttribute('vAlign', 'top');
  111.             _row.lastChild.setAttribute('width', _widths[3]);
  112.             _row.lastChild.appendChild(document.createElement('font'));
  113.             _row.lastChild.lastChild.size = '1';
  114.             _row.lastChild.lastChild.appendChild(document.createTextNode(_fields[_f][4]));
  115.             _holder.firstChild.appendChild(_row);
  116.         }
  117.         var _submit = document.createElement('tr');
  118.         _submit.appendChild(document.createElement('td'));
  119.         _submit.lastChild.setAttribute('class', 'window' + (((_f+1) % 2 == 0)? '1' : '2'));
  120.         _submit.lastChild.setAttribute('className', 'window' + (((_f+1) % 2 == 0)? '1' : '2'));
  121.         _submit.lastChild.setAttribute('align', 'center');
  122.         _submit.lastChild.setAttribute('colSpan', 3);
  123.         var _button = document.createElement('input');
  124.         _button.setAttribute('type', 'button');
  125.         _button.setAttribute('value', 'Post Message');
  126.         _button.onclick = function() { _posting_form.post_it(); };
  127.         _submit.lastChild.appendChild(_button);
  128.         _holder.firstChild.appendChild(_submit);
  129.         document.post_form.style.display = 'none';
  130.         document.post_form.parentNode.insertBefore(_holder,  document.post_form);
  131.     },
  132.     
  133.     post_it: function() {
  134.         // create message and attempt to post it
  135.         this.errors = new Array();
  136.         document.post_form.message.value = document.post_form.subject.value = '';
  137.         var _sub = document.getElementById('0').value;
  138.         _fields[0][5] = true;
  139.         document.post_form.subject.value    = _sub;
  140.         for(_f=0; _f<_fields.length; _f++) {
  141.             if(document.getElementById(_f)) {
  142.                 _value = document.getElementById(_f).value;
  143.                 if(!_value || _value.match(/^s*$/)) {
  144.                     if(_f > 0 && _fields[_f][5])
  145.                         this.show_error('You have left the ' + _fields[_f][1] + ' option empty. This is a required field and as such must contain a value.');
  146.                     else
  147.                         _value = '[i]None[/i]';
  148.                 }
  149.                 document.post_form.message.value += '[b]' + _fields[_f][1] + ':[/b] ' + _value + '\n\n';
  150.             }
  151.         }
  152.         if(this.errors.length == 0)
  153.             document.post_form.post.click();
  154.         else
  155.             this.show_error();
  156.     },
  157.     
  158.     show_error: function() {
  159.         if("undefined" != typeof arguments[0] && arguments[0]) {
  160.             this.errors.push(arguments[0]);
  161.         } else {
  162.             // Show Errors
  163.             if(document.getElementById('status_holder')) {
  164.                 document.getElementById('status_holder_title').innerHTML = "An Error Has Occured";
  165.                 document.getElementById('status_holder_message').innerHTML = this.errors.join("<br />");
  166.                 document.getElementById('status_holder').style.display = 'block';
  167.             }
  168.         }
  169.     }
  170. }
  171.  
  172.  
  173.  
  174. if(document.post_form && location.href.match(/action\/post\/?$/) && vf_username != 'Guest') {
  175.     _posting_form.init();
  176. }
  177. //-->
  178. </script>
 

Re: Code not working.... - Posted By Ross (admin) on 10th Sep 08 at 10:51pm
This line has an unescaped apostrophe {Smile}

_fields[_f++] = new Array('input', 'Battle Phase', ['size', 40, 'maxLength', 50], '', 'This is the phase you attack your opponent\'s monsters or directly to LP.', false);

Re: Code not working.... - Posted By Nick (nickb) on 10th Sep 08 at 11:06pm
in both codes?

Ok it works {Grin}

why do you need a backslash in 's for ? I do not understand that.

but for the first code in the field of "Example RP" I don't want a text field how can I get it to be a name for the Example Rp area?

Ok another thing is, is not for my forum, but for my site that is linked to my forum, this is the first time I have ever encountered this problem.

on my site when I click on Advertise it goes to a blank page, but when you back up the page is goes to the main forum page. I am not releasing the forum/site right now to view. But this is the code for it.

Code:
 
  1. <table border="0">
  2. <tr>
  3. <th>
  4. <p>.:Navigation:.</p>
  5. </th>
  6. </tr>
  7. <tr>
  8. <td><a href="http://ygodr.co.nr" target="_parent">Home</a></td>
  9. </tr>
  10. <tr>
  11. <td><a href="http://ygo.vforums.co.uk" target="_parent">Forum</a></td>
  12. </tr>
  13. <tr>
  14. <td><a href="http://ygo.vforums.co.uk/board/info/" target="_parent">Rules</a></td>
  15. </tr>
  16. <tr>
  17. <td><a href="http://ygodr-news.co.nr" target="_parent">News</a></td>
  18. </tr>
  19. <tr>
  20. <td><a href="http://ygo.vforums.co.uk/board/advertise/" target="_parent">Advertise</a></td>
  21. </tr>
  22. </table>
  23.  
 

Re: Code not working.... - Posted By Ross (admin) on 14th Sep 08 at 9:44pm
 
in both codes?

Ok it works {Grin}

why do you need a backslash in 's for ? I do not understand that.


That description is wrapped in 's, it's what tells the code where that description starts and ends. By having another ' within the text the code thinks that description has ended. The backslash basically tells the code to treat the ' as a standard apostrophe rather than as the end of the description.

Quote:
but for the first code in the field of "Example RP" I don't want a text field how can I get it to be a name for the Example Rp area?


Do you mean you want it as just 1 line of text?

_fields[_f++] = new Array('input', 'Example RP', ['size', 40], '', 'Follow the RP below', false);

Quote:
Ok another thing is, is not for my forum, but for my site that is linked to my forum, this is the first time I have ever encountered this problem.

on my site when I click on Advertise it goes to a blank page, but when you back up the page is goes to the main forum page. I am not releasing the forum/site right now to view. But this is the code for it.


I'm not entirely sure what you mean there? Unless you've already fixed it?