[thelist] php - jscript - onclick event..

bruce bedouglas at earthlink.net
Wed Jun 22 12:15:53 CDT 2005


hi..

a somewhat php/jscript question.......


i have the following onclick that works...
---------------------------------------------------------
<div id="cms-edit-button"><a href="#" onclick="cms_focus ('cms-edit', 1);
cms_focus ('cms-properties', 1); cms_focus ('cms-state', 99); this.blur ();
return false">Account</a></div>


i'd like to be able to have the jscript run if i have a query var foo.
basically, i'd like a way of running the same jscript that gets run during
the onClick, when i select a php function... ie, if i finish a pprocess, i'd
like to set the appropriate page to display.

i thought i could do something like the following:

<?
 if ($_GET['tmp'])
 {
    echo "
      <script language=\"javascript\">
        alert('mmmmmmmm');
	cms_focus ('cms-edit', 1);
      </script>
    ";
    echo "
      <script language=\"javascript\">
	cms_focus ('cms-properties', 1);
      </script>
    ";
    echo "
      <script language=\"javascript\">
	cms_focus ('cms-state', 99);
      </script>
    ";
    echo "
      <script language=\"javascript\">
	return false;
      </script>
    ";
 }
?>

my hope was that this would effectively simulate the running of the
jscript.. but it didn't seem to work. the tabs/screens don't change, which
indicates that the jscript is not running as i thought it would....

the above php/jscript is being called after the jscript cms_focus routine
has been created. in the above sample, i discovered that if i placed all 3
cms_focus calls in the same <script></script> block, only the 1st one seemed
to run... however, even with this, while it appears that each cms_focus call
is being made, there's still not apparent change in the display.

the actual cms_focus routine is listed below. all it really does is to set
the focus of the given div/id the given section/id of 99 is set to be a
block display, with the rest set to be unseen.

any ideas/help would be useful.. i'm pretty sure i'm running into a simple
problem.. this should be doable.

if you need me to, i can supply the entire test php page, as it's not too
long.

also, if you need additional clarification, let me know.. this might be
somewhat jumbled.

thanks

-bruce
bedouglas at earthlink.net


test cms_focus function
<script language="javascript" type="text/javascript">
<!--

function cms_focus (element, index) {

	e = document.getElementById (element);
	p = document.getElementById ('cms-panels');

alert(element+" "+index);
	if (element == 'cms-edit') {
		if (index == 1) {
			document.getElementById('role').style.display = 'none';
			document.getElementById('team').style.display = 'none';
			document.getElementById('disabled').style.display = 'none';
			document.getElementById('public').style.display = 'none';
		} else {
			document.getElementById('role').style.display = 'inline';
			document.getElementById('team').style.display = 'inline';
			document.getElementById('disabled').style.display = 'inline';
			document.getElementById('public').style.display = 'inline';
		//e = document.getElementById (element);
		p = document.getElementById ('cms-panels');
		f = document.getElementById ('subbtn');

		//e.style.left = p.offsetLeft;
		//e.style.top = p.offsetTop - 100;
		f.style.top = p.offsetTop - 40;
		document.getElementById('subbtn').style.display = 'block';
		}
	}

	if (element == 'cms-properties') {
		if (index == 1) {
			document.getElementById('cms-properties').style.display = 'none';
		} else {
			e = document.getElementById ('cms-properties');
			f = document.getElementById ('subbtn');
			p = document.getElementById ('cms-panels');
			e.style.left = p.offsetLeft;
			e.style.top = p.offsetTop - 690;
			f.style.top = p.offsetTop - 650;
			document.getElementById('cms-properties').style.display = 'block';
			document.getElementById('subbtn').style.display = 'block';
		}
	}

	if (element == 'cms-state') {
		if (index == 1) {
			document.getElementById('cms-state').style.display = 'none';
		} else {
			e = document.getElementById ('cms-state');
			f = document.getElementById ('subbtn');
			p = document.getElementById ('cms-panels');
			e.style.left = p.offsetLeft;
			e.style.top = p.offsetTop - 690;
			f.style.top = p.offsetTop - 650;
			document.getElementById('cms-state').style.display = 'block';
			document.getElementById('subbtn').style.display = 'block';
		}
	}

	e.style.zIndex = index;

	if (index == 99) {
		b = document.getElementById (element + '-button');
		b.style.fontWeight = 'bold';
		b.style.backgroundColor = 'eee';
		b.childNodes[0].style.color = 'd60';
	} else {
		b = document.getElementById (element + '-button');
		b.style.fontWeight = 'normal';
		b.style.backgroundColor = 'A9B7C4';
		b.childNodes[0].style.color = 'fff';
	}

	return true;

}

function cms_copy_values (f) {
	edit = document.getElementById ('cms-edit-form');
	f.elements.id.value = edit.elements.id.value;
	f.elements.title.value = edit.elements.title.value;
	xed_copy_value (edit, 'body');
	f.elements.body.value = edit.elements.body.value;

	prop = document.getElementById ('cms-properties-form');
	f.elements.template.value = prop.elements.template.value;
	f.elements.below_page.value = prop.elements.below_page.value;
	f.elements.is_section.value = prop.elements.is_section.value;
	f.elements.keywords.value = prop.elements.keywords.value;
	f.elements.description.value = prop.elements.description.value;
	f.elements.external.value = prop.elements.external.value;
	f.elements.include.value = prop.elements.include.value;

	state = document.getElementById ('cms-state-form');
	f.elements.sitellite_status.value = state.elements.sitellite_status.value;
	f.elements.sitellite_access.value = state.elements.sitellite_access.value;
	f.elements.sitellite_startdate.value =
state.elements.sitellite_startdate.value;
	f.elements.sitellite_expirydate.value =
state.elements.sitellite_expirydate.value;
	f.elements.changelog.value = state.elements.changelog.value;
}

function cms_preview_action (f) {
	cms_copy_values (f);
	return cms_preview (f);
}

function cms_cancel_action (f) {
	cms_copy_values (f);
	if (confirm ('Are you sure you want to cancel?')) {
		return cms_cancel (f);
	}
	return false;
}

// -->
</script>


complete div/onClicks..
----------------------------------
<div id="cms-state-button"><a href="#" onclick="cms_focus ('cms-edit', 1);
cms_focus ('cms-properties', 1); cms_focus ('cms-state', 99); this.blur ();
return false">Access</a></div>
<div id="cms-properties-button"><a href="#" onclick="cms_focus ('cms-edit',
1); cms_focus ('cms-properties', 99); cms_focus ('cms-state', 1); this.blur
(); return false">Contact</a></div>
<div id="cms-edit-button"><a href="#" onclick="cms_focus ('cms-edit', 99);
cms_focus ('cms-properties', 1); cms_focus ('cms-state', 1); this.blur ();
return false">Account</a></div>




More information about the thelist mailing list