Jump to content

Going to url

- - - - -

This topic has been archived. This means that you cannot reply to this topic.
22 replies to this topic

#1
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Okay.. I have a little problem. I have this script:

echo "<script type='text/javascript'>"

				."function go_date(){"

				."var day = document.date.date_day.value;"

				."var month = document.date.date_month.value;"

				."var year = document.date.date_year.value;"

				."var url = '$sel_url' + '&day=' + day + '&month=' + month + '&year=' + year;"

				."document.write(\"<input type='hidden' name='go_date_url' value='url'>\");"

				."window.location=document.date.go_date_url.value;"

				."}";

		echo "</script>";

		echo "<input type='button' value='Go' onClick='go_date();'>";

I'm afraid that problemo is on this line:


"document.write(\"<input type='hidden' name='go_date_url' value='url'>\");"


Maybe someone can tell me what's wrong.. :D

#2
Guest_Jordan_*

Guest_Jordan_*
  • Guests
I looked through it a couple of times but I couldn't find a problem.You should show a JavaScript debugger in FireFox (I think it is called FireBug). Also, if you don't use a debugger I've noticed that IE gives better descriptions and will often cast errors when FF wont.

#3
Guest_Jaan_*

Guest_Jaan_*
  • Guests
I have firebug and umm.. It says this:

Posted Image

I really have no idea what it says :D

#4
Guest_Jordan_*

Guest_Jordan_*
  • Guests
It says that document.date.date_day.value doesn't exist. I'm guessing date is the form and date_day is the element? Do they really exist?

#5
Guest_Jaan_*

Guest_Jaan_*
  • Guests
well.. form's name is "date" and there are drop down those boxed and each of them have a name.. for example:

echo "<select name='year' id='date_year'>";
		echo "<option value='2008' disabled='disabled' selected='selected'>2008</option>";
		echo "<option value='' disabled='disabled'>- -</option>";
		echo "<option value='2008'>2008</option>"
			."<option value='2009'>2009</option>"
			."<option value='2010'>2010</option>"
			."<option value='2011'>2011</option>";
		echo "</select>";


#6
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Try naming the form something different, like formDate. date may be conflicting with something. If that doesn't work try calling it like this:

document.forms[0].date_day.value

Replace the 0 with the form number in your HTML document (starting with form[0] = the 1st form).

#7
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Umm.. I have no idea how many forms I have.. Is there something else i can use?

#8
Guest_Jordan_*

Guest_Jordan_*
  • Guests
Not that I know of. Try changing the name and see what happens. I also just noticed something. If you wanted to call the year you would call like this, right:

document.date.date_year.value

But isn't date_year the ID of that select option? Shouldn't you be calling it like this:

document.date.year.value


#9
Guest_Jaan_*

Guest_Jaan_*
  • Guests
document.date.year.value

Now I use it but now I have 4 javascript errors..

Posted Image

#10
Guest_Jordan_*

Guest_Jordan_*
  • Guests
What is go_date_url? Are you using the ID or the name there?

#11
Guest_Jaan_*

Guest_Jaan_*
  • Guests
."document.write(\"<input type='hidden' name='go_date_url' value='url'>\");"
."window.location=document.date.go_date_url.value;"

go_date_url is this hidden input thingy

#12
Guest_Jaan_*

Guest_Jaan_*
  • Guests
Here's my form:

echo "<form name='date'>";
	echo "<select name='day' id='date_day'>";
		echo "<option value='$today' selected disabled>$today</option>";
		echo "<option value='' disabled>- -</option>";
		$num = "1";
		while($num<=$day){
			
			echo "<option value='$num'>$num</option>";
			$num++;
			
		}		               	
		echo "</select>";		
		$months = array("january", "february", "march", "april", "may", "june", "july", "august", "september", "october", "november", "december");	
		echo "<select name='month' id='date_month'>";
		echo "<option value='".strtolower(date("F"))."' selected disabled>".date("F")."</option>";
		echo "<option value='' disabled>- -</option>";
		$num = "0";
		while($num<=11){
			
			echo "<option value='$months[$num]'>".ucwords($months[$num])."</option>";
			$num++;
			
		}		               	
		echo "</select>";		
		echo "<select name='year' id='date_year'>";
		echo "<option value='2008' disabled='disabled' selected='selected'>2008</option>";
		echo "<option value='' disabled='disabled'>- -</option>";
		echo "<option value='2008'>2008</option>"
			."<option value='2009'>2009</option>"
			."<option value='2010'>2010</option>"
			."<option value='2011'>2011</option>";
		echo "</select>";
			
		$sel_url = $_SERVER['REQUEST_URI'];
		$sel_url = explode("/", $sel_url);
		$sel_url = $sel_url['2'];
		
		echo "<script type='text/javascript'>"
				."function go_date(){"
				."var day = document.date.day.value;"
				."var month = document.date.month.value;"
				."var year = document.date.year.value;"
				."var url = '$sel_url' + '&day=' + day + '&month=' + month + '&year=' + year;"
				."document.write(\"<input type='hidden' name='go_date_url' value='url'>\");"
				."window.location=document.date.go_date_url.value;"
				."}";
		echo "</script>";
		echo "<input type='button' value='Go' onClick='go_date();'>";
		echo "</form>";