Jump to content

JavaScript pitanje


cali

Recommended Posts

Imam pitanje koje večeras nisam sposoban da rešim, jer mi je mozak zakucao.

Treba da napravim stranu koja će tražiti da unesem neku vrednost, i ako je ta vrednost cifra od 1 do 5 da mi izbaci odgovarajuću vrednost.

Problem je što nisam lepo odredio definiciju varijable, jer šta god da unesem skripta prepozna kao nešto šesto (default u switch petlji)

Imate li ideju gde sam se sjebao?

I bonus pitanje, koji debugger preporučujete za JS?

<HTML> 

<HEAD> 

<TITLE>

Meh skripta

</TITLE> 

<script LANGUAGE="JavaScript">

	function DaniUNedelji(podatak){

		var podatak = document.form1.podatak.value;

		switch(podatak)

			{

			case 1:

				document.writeln("Nedovoljan");

			break;

			case 2:

				document.writeln("Dovoljan");

			break;

			case 3:

				document.writeln("Dobar");

			break;

			case 4:

				document.writeln("Vrlo Dobar");

			break;

			case 5:

				document.writeln("Odlican");

			break;

			default:

				document.writeln("Meh.");

			}

	}

</SCRIPT>

</HEAD> 

<BODY> 

	<FORM name="form1" METHOD="POST" enctype=application/x-www-form-urlencoded>

		Ime:<BR> <INPUT TYPE="text" NAME="podatak"><BR>

		<INPUT TYPE="BUTTON" OnClick="DaniUNedelji(podatak)" VALUE="Submit">

	</FORM>

</SCRIPT> 

</BODY> 

</HTML>

Edited by cali
Link to comment
Share on other sites

Malo kafe i sna rešilo problem. Koliko sam skapirao definisao sam ulazni podatak kao tekst, a Case komandi sam zadao da traži brojeve. Prepravljanje iz case 1 u case "1" je rešilo problem. Hvala što ste prisustvovali mom rantu :D

A sada slika jelena koji češe muda.

moose_scratching_his_balls_with_antlers.jpg

Link to comment
Share on other sites

prosledjujes mu ceo element ovim, umesto samo vrednost

OnClick="DaniUNedelji(podatak)"

probaj ovako nesto:

<INPUT TYPE="text" ID="podatak" NAME="podatak">

<INPUT TYPE="BUTTON" OnClick="DaniUNedelji(document.getElementById('podatak').value)" VALUE="Submit">

ja koristim firebug za sve js-related akcije

The people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same way in any country.

Link to comment
Share on other sites

prosledjujes mu ceo element ovim, umesto samo vrednost

OnClick="DaniUNedelji(podatak)"

probaj ovako nesto:

<INPUT TYPE="text" ID="podatak" NAME="podatak">

<INPUT TYPE="BUTTON" OnClick="DaniUNedelji(document.getElementById('podatak').value)" VALUE="Submit">

Hvala, ovo je def. bolje od onoga što sam ja sklepao.

Link to comment
Share on other sites

a naravno mozes i samo podatak.value da koristis umesto celog getDocumentById, ali je praksa da se koristi ID

The people can always be brought to the bidding of the leaders. That is easy. All you have to do is tell them they are being attacked and denounce the pacifists for lack of patriotism and exposing the country to danger. It works the same way in any country.

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...