www.webdeveloper.com
Results 1 to 10 of 10

Thread: [RESOLVED] Help with content changing in Table

  1. #1
    Join Date
    Nov 2011
    Posts
    5

    resolved [RESOLVED] Help with content changing in Table

    Hello all.

    I have a problem with changing the pictures in cells in the javascript created table.
    I need to change the picture in specific cells. Like: 5.th row, 4.th cell and so on.

    Here is the code:
    Code:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <title>Untitled Document</title>
    <script language="JavaScript" type="text/javascript">
    
    function createfield()
    {
    	var hosz_val = document.Jatektermeretek.hosz.value;
    	var szel_val = document.Jatektermeretek.szél.value;
    	var body= document.getElementsByTagName("body") [0];
    	var jatekter= document.createElement("table");
    	var jatekter_body = document.createElement("tbody");
    	
    		for (var j=0; j< hosz_val; j++)
    			{
    				var sor= document.createElement("tr");
    				
    				for (var i=0; i< szel_val; i++)
    				{
    					var cella= document.createElement("td");
    					cellaimg= document.createElement("img");
    					cellaimg.setAttribute("src","../pics/houdini_pics/field_bgimg.png");
    					cella.appendChild(cellaimg);
    					sor.appendChild(cella);
    				}
    				jatekter_body.appendChild(sor);
    				jatekter.appendChild(jatekter_body);
    			}
    			body.appendChild(jatekter);
    			jatekter.setAttribute("border","0");
    			jatekter.setAttribute("align", "center");
    			jatekter.setAttribute("cellPadding", "0");
    			jatekter.setAttribute("celling", "0");
    			
    			var x=document.getElementsByTagName("td");
    			alert(x.length);
    			x[21].setAttribute("")
    	}
    function numcheck()
    {
    	var hosz_val = document.Jatektermeretek.hosz.value;
    	var szel_val = document.Jatektermeretek.szél.value;
    	if (hosz_val < 5 || szel_val < 5)
    		{
    			alert("A megadott értékek túl alacsonyak, a játék nem kivitelezheto" + '\n' + "Ne feledje: A több néha jobb");
    		}
    	else
    		{
    			createfield();
    		}
    	}
    </script>
    <div align="center">
      <h1><span class="style1">Első Javascript beadand&oacute;</span></h1>
      <h2>Houdini Kalapja</h2>
    </div>
      <h3 align="left">J&aacute;t&eacute;kszab&aacute;ly:</h3>
      <blockquote><p align="left"><strong>1.:</strong> Adja meg a j&aacute;t&eacute;kt&eacute;r m&eacute;reteit.<br />
            <strong>2.:</strong> A fel, le , jobbra, balra gombokkal a kalapot mozgatva el kell kapni a nyulat.<br />
              <strong>3.:</strong> A kalap mozgat&aacute;s k&ouml;zben forog, a ny&uacute;lra <strong>r&aacute; kell h&uacute;zni</strong> a kalapot! <br />
              <strong>4.:</strong> A j&aacute;t&eacute;k akkor &eacute;r v&eacute;get sikeresen, ha  r&aacute;tett&uuml;k a ny&uacute;lra a kalapot. </p>
      </blockquote>
      <br />
      <br />
      <form action="" method="get" name="Jatektermeretek" id="meretek">
      	<div align="left">
      	  <blockquote>
      	    <p>Adja meg a játéktér méreteit:
      	      <input name="hosz" type="text" value="0" size="4" maxlength="2" />
      	      X
      	      <input name="sz&eacute;l" type="text" value="0" size="4" maxlength="2" />
    		    &nbsp;&nbsp;<input name="submit" type="button" value="Indul" onclick="numcheck()" />
      	    </p>
      	    <p>&nbsp;</p>
      	  </blockquote>
      	</div>
      </form>
    </html>

  2. #2
    Join Date
    Nov 2011
    Location
    South-eastern United States
    Posts
    7
    Do you want to change the image depending on a certain action from the user?

  3. #3
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    Take care and eliminate accents in names or identifiers...

    A document.Jatektermeretek.sz&#233;l.value; can not give the value of an input of name sz&eacute;l (the $eacute give the &#233; in HTML but not in javascript). Change at first this name with a szel.

    Then work with a debugger like Firebug with FireFox or other development error console...

  4. #4
    Join Date
    Nov 2011
    Posts
    5

    Thank You

    Thank you for the help, I did just that, and the problem at hand has been dealt with by now.

    Now I have a different problem.

    The code:

    Code:
    document.onkeyup = alert("megnyomtad");
    Doesn't work for me. For one as soon as I open the page it shows the alert box, and it doesn't work again. As soon as alertbox is closed, no matter what I do , it doesn't show up again.

    Could you help with this too?

  5. #5
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    Document.onkeyup wait a function and not an instruction ? Try :

    Code:
    function lrt(){alert("megnyomtad");}
    document.onkeyup = lrt;
    
    // or with an anonymous fonction
    document.onkeyup=function(){alert("megnyomtad");}

  6. #6
    Join Date
    Nov 2011
    Posts
    5
    Thanks it works, but it reacts when i press ENTER as well (when I want to close alert window).
    It isn't bad (filtering will take care of that), but just out of curiosity: why is it so?

    Thnks again, you're a great help.

    I almost forgot, how to deal with the fact that IE and FF works with it differently?
    Last edited by PSyho; 11-05-2011 at 10:31 AM.

  7. #7
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    Try this
    Code:
    document.onkeyup = function(e){var k=e?e.which:window.event.keyCode,t=e?e.target:window.event.srcElement;
    	if (k==13) return;// for Enter
    	alert("The key is "+k);
    	// work with other keys and t the target 
    }

  8. #8
    Join Date
    Nov 2011
    Posts
    5
    Thanks, but what is that
    Code:
    t=e?e.target:window.event.srcElement;
    for?

  9. #9
    Join Date
    Nov 2011
    Posts
    5
    Next question( hopefully the last)

    I need the innerHTML src attributes of the pictures.

    if the src value of image in cell id x is 1.png, then the src value of image in cell id x+1 needs to be 2.png.

    And vice versa.

  10. #10
    Join Date
    Oct 2010
    Location
    Versailles, France
    Posts
    1,290
    First question. The argument e (the event object) of the function do not exist with Internet Explorer but is done by window.event.
    To determine the key we test e, to keep e.which (if e exist) and window.event.keyCode (if e do not exist). It the same to determine the target (usually the input where the key board is used) t is given by e.target (if e exist) and window.event.srcElement (if not). You can remove this values, if you have not to work with this target.

    I do not understand the second question the innerHTML of a cell will give all the tag img and the src attribute of the picture...

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center

"

"

X vBulletin 4.2.2 Debug Information

  • Page Generation 0.14335 seconds
  • Memory Usage 2,942KB
  • Queries Executed 15 (?)
More Information
Template Usage (33):
  • (1)SHOWTHREAD
  • (1)ad_footer_end
  • (1)ad_footer_start
  • (1)ad_global_above_footer
  • (1)ad_global_below_navbar
  • (1)ad_global_header1
  • (1)ad_global_header2
  • (1)ad_navbar_below
  • (1)ad_showthread_firstpost_sig
  • (1)ad_showthread_firstpost_start
  • (1)ad_thread_first_post_content
  • (1)ad_thread_last_post_content
  • (5)bbcode_code
  • (1)footer
  • (1)forumjump
  • (1)forumrules
  • (1)gobutton
  • (1)header
  • (1)headinclude
  • (1)headinclude_bottom
  • (10)memberaction_dropdown
  • (1)navbar
  • (4)navbar_link
  • (1)navbar_moderation
  • (1)navbar_noticebit
  • (1)navbar_tabs
  • (2)option
  • (10)postbit
  • (10)postbit_onlinestatus
  • (10)postbit_wrapper
  • (1)spacer_close
  • (1)spacer_open
  • (1)tagbit_wrapper 

Phrase Groups Available (6):
  • global
  • inlinemod
  • postbit
  • posting
  • reputationlevel
  • showthread
Included Files (26):
  • ./showthread.php
  • ./global.php
  • ./includes/class_bootstrap.php
  • ./includes/init.php
  • ./includes/class_core.php
  • ./includes/config.php
  • ./includes/functions.php
  • ./includes/functions_navigation.php
  • ./includes/class_friendly_url.php
  • ./includes/class_hook.php
  • ./includes/class_bootstrap_framework.php
  • ./vb/vb.php
  • ./vb/phrase.php
  • ./includes/functions_facebook.php
  • ./includes/functions_calendar.php
  • ./includes/functions_bigthree.php
  • ./includes/class_postbit.php
  • ./includes/class_bbcode.php
  • ./includes/functions_reputation.php
  • ./includes/functions_notice.php
  • ./packages/vbattach/attach.php
  • ./vb/types.php
  • ./vb/cache.php
  • ./vb/cache/db.php
  • ./vb/cache/observer/db.php
  • ./vb/cache/observer.php 

Hooks Called (73):
  • init_startup
  • friendlyurl_resolve_class
  • init_startup_session_setup_start
  • database_pre_fetch_array
  • database_post_fetch_array
  • init_startup_session_setup_complete
  • global_bootstrap_init_start
  • global_bootstrap_init_complete
  • cache_permissions
  • fetch_postinfo_query
  • fetch_postinfo
  • fetch_threadinfo_query
  • fetch_threadinfo
  • fetch_foruminfo
  • load_show_variables
  • load_forum_show_variables
  • global_state_check
  • global_bootstrap_complete
  • global_start
  • style_fetch
  • global_setup_complete
  • showthread_start
  • showthread_getinfo
  • strip_bbcode
  • friendlyurl_clean_fragment
  • friendlyurl_geturl
  • forumjump
  • cache_templates
  • cache_templates_process
  • template_register_var
  • template_render_output
  • fetch_template_start
  • fetch_template_complete
  • parse_templates
  • fetch_musername
  • notices_check_start
  • notices_noticebit
  • process_templates_complete
  • friendlyurl_redirect_canonical
  • showthread_post_start
  • showthread_query_postids
  • showthread_query
  • bbcode_fetch_tags
  • bbcode_create
  • showthread_postbit_create
  • postbit_factory
  • postbit_display_start
  • postbit_imicons
  • bbcode_parse_start
  • bbcode_parse_complete_precache
  • bbcode_parse_complete
  • postbit_display_complete
  • memberaction_dropdown
  • tag_fetchbit
  • tag_fetchbit_complete
  • forumrules
  • navbits
  • navbits_complete
  • build_navigation_data
  • build_navigation_array
  • check_navigation_permission
  • process_navigation_links_start
  • process_navigation_links_complete
  • set_navigation_menu_element
  • build_navigation_menudata
  • build_navigation_listdata
  • build_navigation_list
  • set_navigation_tab_main
  • set_navigation_tab_fallback
  • navigation_tab_complete
  • fb_like_button
  • showthread_complete
  • page_templates