Jump to content

javascript prompt blank

Swiebertjeee
Go to solution Solved by Mr_KoKa,

I'm not sure what you want to achieve, but here is a code that will loop until you fill up prompt field.

 

http://jsfiddle.net/qschpy3c/

do {    var str = prompt(":");} while(!str || str.length == 0);alert(str);

Some more about your code:

 

I've had a loot of ideas what you might wanted to achieve, but you probably trying to make klantnaam2 a function that will display text "Sorry wat is uw naam?" and klantnaam variable content.

My guess is:

var klantnaam2 = function(){  alert("Sorry wat is uw naam? " + klantnaam);}

Second thing, your else if, it has 2 conditions but actualy only one is variable, if(false) will be never fulfilled. You probably want to have:

else if (klantnaam == null || klantnaam == false)

But to check if string is empty you just need to check its length. You can fist check if it's not null, but prompt will return string, so it's not necessary.

 

To call function you need to use () operator, so instead of klantnaam; you should use:

klantnaam();

My last guess is http://jsfiddle.net/9nvsLugq/

function klantnaam2(){    alert("Sorry wat is uw naam?");    klantnaam();}function klantnaam(){    var str = prompt("vul hier uw naam in");    if(str == "")    {        klantnaam2();    }    else if(str == null || str == false)    {        klantnaam2();    }}klantnaam();

Also you can bring all if's together into one, excluding checking for false

if(str == null || str == ""){  klantnaam2();}

and use do-while loop instead of functions. And you will end up with a code I pasted on top of this post.

so I'm doing this javascript but I got stuck on javascript I need to make a prompt which cant be left blank I need to create a alert which redirect them back to previous prompt so I made this but It will not work have no clue O.o

var klantnaam=prompt("vul hier uw naam in");    var klantnaam2=alert("Sorry wat is uw naam?")+klantnaam;    if(klantnaam=="")    {        klantnaam2;    }    else if(klantnaam==null || false)    {        klantnaam2;    }

It will show the alert but the +klantnaam does not work how can I fix this?

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure what you want to achieve, but here is a code that will loop until you fill up prompt field.

 

http://jsfiddle.net/qschpy3c/

do {    var str = prompt(":");} while(!str || str.length == 0);alert(str);

Some more about your code:

 

I've had a loot of ideas what you might wanted to achieve, but you probably trying to make klantnaam2 a function that will display text "Sorry wat is uw naam?" and klantnaam variable content.

My guess is:

var klantnaam2 = function(){  alert("Sorry wat is uw naam? " + klantnaam);}

Second thing, your else if, it has 2 conditions but actualy only one is variable, if(false) will be never fulfilled. You probably want to have:

else if (klantnaam == null || klantnaam == false)

But to check if string is empty you just need to check its length. You can fist check if it's not null, but prompt will return string, so it's not necessary.

 

To call function you need to use () operator, so instead of klantnaam; you should use:

klantnaam();

My last guess is http://jsfiddle.net/9nvsLugq/

function klantnaam2(){    alert("Sorry wat is uw naam?");    klantnaam();}function klantnaam(){    var str = prompt("vul hier uw naam in");    if(str == "")    {        klantnaam2();    }    else if(str == null || str == false)    {        klantnaam2();    }}klantnaam();

Also you can bring all if's together into one, excluding checking for false

if(str == null || str == ""){  klantnaam2();}

and use do-while loop instead of functions. And you will end up with a code I pasted on top of this post.

Link to comment
Share on other sites

Link to post
Share on other sites

I'm not sure what you want to achieve, but here is a code that will loop until you fill up prompt field.

 

http://jsfiddle.net/q5mtdv5p/

 

Only issue is that when you press "cancel" browser will stop executing the script, and I guess there is nothing you can do about it, at least using prompt function. You can always build HTML modal prompt window, so it will appear on the top of the page view.

What I want to achieve is as soon they click on ok on the alert box they will return back to the prompt (klantnaam)

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

So it is, you can take close look to code I provide you in my last post, it will keep prompting user for data until user will fill prompt field.

Instead of checking equality with "" and then if it is null or anything you may just want to check if length of string that user provide you by prompt is not 0.

Link to comment
Share on other sites

Link to post
Share on other sites

the last one is what I ment thank you!! :D

Beneath this mask there is an idea, and ideas are bulletproof.

Link to comment
Share on other sites

Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×