Jump to content

My script not working... I have revised a number of times but...


clonetrooper9494

Recommended Posts

I was editing my script... and suddenly it doesn't work. As a matter of fact I have already had to start from scrtach once because the script stopped working when I added a line of code like: "var subd2ff = 'testing';" the script altogether stopped working even after I took it out. I don't know if IE is acting up or something... but it's making me really mad. Here is the webpage: http://free.hostultra.com/~clonetrooper/test_file.html

<html><head><script language=JavaScript>function open(div_id_1, link1, name1){var subd1ff = '<a href=' + link1.value + '>' + name1.value + '</a>';div_id_1.innerHTML = 'subd1ff';}</script></head><body><a href="#" onclick="open(div1, l1, n1)">TEST</a><br>L<input type="text" id="l1"><br>N<input type="text" id="n1"><br><div id="div1"></div></body></html>

Link to comment
Share on other sites

Maybe you can try this instead:<a href="#" onclick="open(document.getElementById('div1'), document.getElementById('l1').value, document.getElementById('n1').value)">TEST</a><br>

Link to comment
Share on other sites

Let me try that... I tried it once befor but it didn't work...By the way, does it work on your computer? http://free.hostultra.com/~clonetrooper/test_file.htmlThe tricky thing is I want about 16 of those box pairs... :), and need the most efficient way or eles I would have about 16 scripts!NOTE: I was in the middle of typing this, and I tried it out... it works! thanks every one... I may need some help though... another time saver!

Link to comment
Share on other sites

I am planning on having a costumizeable webpage with a menu and a submenu, all of which the person can choose the text (and links)... is there a script that hides a textarea or an input? I was planing on making them all hide the info in hidden inputs sacttered every where, but I found it would involve a huge code... I saw this once or twice on google... "document.GetElementById('...')style.display = none;" does that really work, did I read it wrong? I tried it, but it didn't work.

Link to comment
Share on other sites

Every thing is falling in to place! :)... oh wait...Is there a script that would fill in the value of an input if its id was like "test7" and the url was ....html?test7=dfjgkhyiu , test7 on onload would be come that in the url???I had another topic on this type of url reading thing, but it *died*

Link to comment
Share on other sites

You need a server side language, and you can't test that on your computer.Here's how to get things from the URL with PHP:Given the url example: .../file.php?test7=something<?php echo $_GET['test7']; ?> will return "something".<?php echo "<input type=\"text\" value=\"".$_GET['test7']."\" />"; ?> will return <input type="text" value="something" />

Link to comment
Share on other sites

I might go over to a PHP board... I want to do that for 16 inputs... :)Do I paste that code 16 times with different values and stuff in there?Because the URL would be ....html?test1=dfgjk&test=2=dfgjk&test3=dfgjkwould that PHP code work still?

Link to comment
Share on other sites

for each component of the query string put one $_GET value:url: ?a=1&b=5&s=something&another=99<?phpecho $_GET['a'];echo $_GET['b'];echo $_GET['s'];echo $_GET['another'];?>returns: 15something99

Link to comment
Share on other sites

CloneTrooper, sorry I didn't see your posts about the GET function. I'll try to explain it...Here's the code again:

window.GET = function(){	var url = window.location.href;	var array = url.indexOf('#') == -1 ?				url.substring(url.indexOf('?') + 1).split(/&;/):				url.substring(url.indexOf('?') + 1, url.indexOf('#')).split(/&;/);							//URLs can be like either "sample.html?test1=hi&test2=bye" or								//"sample.html?test1=hi;test2=bye"	window._GET = {};	for(var i = 0; i < array.length; i++){		var assign = array[i].indexOf('=');		if(assign == -1){			_GET[array[i]] = true;//if no value, treat as boolean		}else{			_GET[array[i].substring(0, assign)] = array[i].substring(assign + 1);		}	}}

If you're interested in how it works, read on; if not, scroll down to the instructions.

	var url = window.location.href;

"Get the URL from the location bar."

	var array = url.indexOf('#') == -1 ?

"Does the URL contain '#'?"

				url.substring(url.indexOf('?') + 1).split(/&;/):

"If not, make array equal to the piece of the URL from the character directly after the '?' to the end, split into the pieces divided by '&'s and ';'s."

				url.substring(url.indexOf('?') + 1, url.indexOf('#')).split(/&;/);

"If so, make array equal to the piece of the URL from the character directly after the '?' to the '#', split into the pieces divided by '&'s and ';'s."

	window._GET = {};

"Make GET a global variable and put an empty object (so no fields are reserved for array things like 'length') in it."

	for(var i = 0; i < array.length; i++){

"For each of the indices in array,...

		var assign = array[i].indexOf('=');

"Get the position of '=' in the current array element."

		if(assign == -1){

"If the current array element doesn't contain '=', ..."

			_GET[array[i]] =  true;

"In the _GET object, associate the value of this array element with a boolean value of true."

		}else{

"Otherwise,..."

			_GET[array[i].substring(0, assign)] =  array[i].substring(assign + 1);

"In the _GET object, associate the value of this array element from its first to that '=' (the name of the GET parameter) with the value of the same array element from just after that '=' to the end (the value of the GET parameter)."This is how you make sure all GET parameters are available from anywhere in your script:

window.GET();

Simple GET() would also work, unless a variable with an identical name were declared locally. (If another variable named GET is declared globally, one of these two variables would overwrite the other, and the function might not work.)So, if the URL is example.com/test.html?test1=hi&test2=bye, then this:

window.GET();alert(_GET['test1']);alert(_GET.test1);alert(_GET['test2']);alert(_GET.test2);

will alert "hi" twice, then "bye" twice.

Link to comment
Share on other sites

It's all right, I found the page will have less text if I use simple PHP scripting and JavaScript... I sort of fused them... well, just take a look if you want:

<html><head><title>Welcome!</title><script>function layout_check(){document.getElementById('top_banner').innerHTML = '<img src=http://free.hostultra.com/~clonetrooper/images/layouts/topbanner_' + document.getElementById('top_banner').innerHTML + '_number.gif>';}</script><head><body onload="layout_check()"><table><tr><td><div id="top_banner"><?php echo $_GET["_topbanner"]; ?></div></td></tr><tr><td></body></html>

Depending on the url( http://free.hostultra.com/~clonetrooper/in...topbanner=test1 ), a different image pops up... (You may be able to do that with PHP, but I still am having trouble understanding the PHP tutorials.)

Link to comment
Share on other sites

Umm... I hope that top banner isn't an ad, because if it is, very few ads will show on your page. People will just remove the parameter from the URL.And here's the equivalent without JavaScript. It's a good demonstration of what PHP does; notice that PHP doesn't care that the call to echo is in the middle of a string. (FYI, you can also echo into any other client language, including JavaScript and CSS.)

<html>	<head>		<title>Welcome!</title>	<head>	<body>		<table>			<tr>				<td>					<div id="top_banner">						<img src="http://free.hostultra.com/~clonetrooper/images/layouts/topbanner_<?php echo $_GET['_topbanner']; ?>_number.gif">					</div>				</td>			</tr>			<tr>		<td>	</body></html>

Link to comment
Share on other sites

No, it is not an ad, the page is going to have costomizable menu with links, the top banner is going to be what ever they want, I'm still working on it and playing around with this whole concept.And thanks for that info... it will make the page have less HTML and JavaScript in the long run. The only problem I might run in to is making the page costomizable, but if you can include it in JS tags too... I should be able to do this once I think about for a while!

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...