...

View Full Version : Prompt Alert



ccarrin2
01-07-2012, 01:03 AM
When you do an alert confirm you can make if statements to say if they click ok do this and if they click cancel stop the program. Well I am trying to make a prompt that first asks the user to enter in a url and after they do and click enter they url is wraped with img tags.

I would like to make it so that if the user clicks cancel the program ends b/c right now if the user click okay with no value the result is and if the user clicks cancel the result is null. Any step in the right direction would be greatly appreciated!


<script language="javascript">
function imgGenerator(){
var question=confirm("Would you like to share an image?");
if (question==true){
var obj=document.getElementById("mngl-board-post-input");
var imgurl = prompt("To Share an image paste the image url here");
var txt=document.createTextNode(""+imgurl+"");
obj.appendChild(txt);
}
else {}
}
</script>

xelawho
01-07-2012, 03:01 AM
I think this covers all your bases...



<script language="javascript">
function imgGenerator(){
var question=confirm("Would you like to share an image?");
if (question==true){
var obj=document.getElementById("mngl-board-post-input");
var imgurl = prompt("To Share an image paste the image url here");
if (imgurl==null||imgurl==""){return;}
var txt=document.createTextNode(""+imgurl+"");
obj.appendChild(txt);
}
else {
return;
}
}
</script>

felgall
01-07-2012, 09:45 PM
What about if someone clicks the "disable JavaScript" button in the confirm instead of the "Ok" or "Cancel" button?

You would do better to create your own lightbox dialog to collect the information rather than using one that has additional options for debugging purposes in some browsers.

Krupski
01-08-2012, 02:50 AM
try this:



var url = prompt('Please enter the URL of your image:', 'http://') || false;
if (url) {
url = url.replace(/(?:http:\/\/)+/gi, 'http://') || false; // fix multiple http
}
if (url && (url !== 'http://')) {
/* use the url here */
} else {
/* user cancelled */
}

Krupski
01-08-2012, 02:53 AM
What about if someone clicks the "disable JavaScript" button in the confirm instead of the "Ok" or "Cancel" button?


What browser has "disable js" as an option for an alert?

And, anyone who browses with JS turned off may as well go back to paper bulletin boards and cup-with-string communications...



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum