Refresh на страницата заради JS... +1

Post Reply
User avatar
Gh057
Нов
Нов
Posts: 102
Joined: Sun Feb 24, 2008 5:28 pm

Refresh на страницата заради JS... +1

Post by Gh057 » Thu Jun 18, 2009 2:48 pm

Тепърва прохождам в JavaScript-а. Ето скрипта, които написах, НО всеки път щом го изпълни refresh-ва страницата и стойностите написани в textfield-овете се изтриват. Защо става така, не е нормално да се refresh-ва страницата? Какво пропускам?

Code: Select all

<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Untitled Document</title>

</head>

<body>
<script type="text/javascript">
<!--
function proba&#40;&#41; 
&#123;
	try
	&#123;
		var a1 = new Number &#40;document.getElementById&#40;"tf"&#41;.value&#41;;
		var a2 = new Number &#40;document.getElementById&#40;"tf2"&#41;.value&#41;;
		
		if &#40;a1 == 5&#41;
		&#123;
			document.getElementById&#40;"tf3"&#41;.value = "Pyrvoto chislo e 5";
		&#125; 
		else
		&#123;
			throw "Exs1";
		&#125;
	&#125;
	catch&#40;err&#41;
	&#123;
		if &#40;err == "Exs1"&#41;
		&#123;
			txt	= "There was an error on this page.\n\n";
  			txt += "Click OK to continue.\n\n";
			
  			alert&#40;txt&#41;;
		&#125;	
	&#125;
	//document.write&#40;a1 + a2&#41;;
&#125;
-->
</script>

<form id="form1" name="form1" method="post" action="#">
  <input name="tf" type="text" id="tf" />
  +
  <input name="tf2" type="text" id="tf2" />
  =
  <input name="aa" type="submit" id="aa" value="Click" onclick="javascript&#58; proba&#40;&#41;;" />
<br /><br />
  <textarea name="textfield" cols="50" rows="4" id="tf3"></textarea>
</form>

</body>
</html>
Поздрави

User avatar
bafitu
Много Редовен
Много Редовен
Posts: 1509
Joined: Mon Dec 12, 2005 9:12 am
Answers: 102
Location: Somewhere around nothing..

Post by bafitu » Thu Jun 18, 2009 2:53 pm

<form id="form1" name="form1" method="post" action="#" onsubmit='return false;'>

;)

User avatar
Gh057
Нов
Нов
Posts: 102
Joined: Sun Feb 24, 2008 5:28 pm

Post by Gh057 » Thu Jun 18, 2009 3:42 pm

+1 мерси

Post Reply