SitePoint Sponsor

User Tag List

Results 1 to 4 of 4
  1. #1
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Question javascript generated in javascript ptoblem with ie6

    I've got a javascript created inside a javascript. The first one should generate (onload) the code of the second one that has to be executed onclick. It works perfectly in firefox, but doesn't in internet explorer6: onclick nothing happens, but with a debug alert I can see it generated.
    Any idea?
    Thank you.
    triverio

  2. #2
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,053
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    code

    It may help to see the code and be able to test it.

  3. #3
    SitePoint Member
    Join Date
    May 2007
    Posts
    3
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Quote Originally Posted by Mittineague View Post
    It may help to see the code and be able to test it.
    Here it is:

    this is the onload script
    Code:
    <script language="javascript" defer>
      window.onload = function() {
       <?php
          if (count($timestamp_error) != 0) {
            arrayToJS4($timestamp_error, 'valori');
          }
          else {
            echo('valori = null;');
          }
        ?>
        initFields(valori);
      }
    </script>
    And this are the scripts called from initFields

    Code:
    var counter = 0;
    
    function addDynDate(bound, counter) {
      if (bound != 'start' && bound != 'end') {
        return false;
      }
    
      var out = '<script type="text\/javascript">' +
    'alert("eseguito!");' +
                'function updateSelect' + counter + '(cal) {' +
                  'var date = cal.date;' +
                  'var selectMonth = $("fare_period_' + bound + '_month_' + counter + '");' +
                  'selectMonth.selectedIndex = date.getMonth();' +
                  'var selectDay = $("fare_period_' + bound + '_day_' + counter + '");' +
                  'selectDay.selectedIndex = (date.getDate() - 1);' +
                  'var selectYear = $("fare_period_' + bound + '_year_' + counter + '");' +
                  'selectYear.selectedIndex = (date.getFullYear() - 2007);' +
                '}' +
                '$("trigger_fare[period][' + bound + ']_' + counter + '").disabled = false;' +
                'Calendar.setup({' +
                  'inputField : "fare[period][' + bound + ']_rich_sel_date_' + counter + '",' +
                  'ifFormat : "%Y-%m-%d",' +
                  'button : "trigger_fare[period][' + bound + ']_' + counter + '",' +
                  'singleClick : true,' +
                  'onUpdate : updateSelect' + counter + ',' +
                  'showsTime : false,' +
                  'range : [2007, 2009],' +
                  'showOthers : false,' +
                  'cache : 1,' +
                  'weekNumbers : false,' +
                  'firstDay : 1' +
                '});' +
              '<\/script>';
    alert(out);
      return out;
    }
    
    function buildFields(start, end, index) {
    	var newFields = $('readroot').cloneNode(true);
    	newFields.id = 'period_' + index;
    	newFields.style.display = 'block';
    
    	newFields.innerHTML = newFields.innerHTML + addDynDate('start', index) + addDynDate('end', index);
    
    	var newField = newFields.childNodes;
    	for (var i = 0; i < newField.length; i++) {
    		var theName = newField[i].name
    		var theId = newField[i].id
    		if (theName) {
    			newField[i].name = theName + '[' + index + ']';
    		}
    		if (theId) {
    			newField[i].id = theId + '_' + index;
    		}
    	}
    
    	var insertHere = $('writeroot');
    	insertHere.parentNode.insertBefore(newFields, insertHere);
    
    	selectDay = $("fare_period_start_day_" + index);
      selectDay.selectedIndex = start['day'][index] - 1;
    	selectMonth = $("fare_period_start_month_" + index);
      selectMonth.selectedIndex = start['month'][index] - 1;
    	selectYear = $("fare_period_start_year_" + index);
      selectYear.selectedIndex = start['year'][index] - 2007;
    
      selectDay = $("fare_period_end_day_" + index);
      selectDay.selectedIndex = end['day'][index] - 1;
    	selectMonth = $("fare_period_end_month_" + index);
      selectMonth.selectedIndex = end['month'][index] - 1;
    	selectYear = $("fare_period_end_year_" + index);
      selectYear.selectedIndex = end['year'][index] - 2007;
    }
    
    function initFields(value) {
      if (value==null) {
        moreFields();
      }
      else {
        for (var k = 1; k < value['start']['day'].length; k++) {
          buildFields(value['start'], value['end'], k);
        	counter++;
        }
      }
    }

  4. #4
    Programming Team silver trophybronze trophy
    Mittineague's Avatar
    Join Date
    Jul 2005
    Location
    West Springfield, Massachusetts
    Posts
    17,053
    Mentioned
    187 Post(s)
    Tagged
    2 Thread(s)

    IE problem

    So you see both the script in the "out" alert, and the "eseguito!" alert?
    Does taking out the "defer" make any difference?


Bookmarks

Posting Permissions

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