Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 465
  • Last Modified:

Alert Box - DropDown List

I'm trying to create a dropdown list within an alert box using JavaScript.  How does that code look?  Thanks for any help you can provide.
0
luckydog374
Asked:
luckydog374
  • 8
  • 4
  • 2
  • +3
2 Solutions
 
jonnalCommented:
hi try this

<input TYPE="TEXT" NAME="TT" ID="KK"><br><br><br><br><br>
<select NAME="TEMP" onChange="alert(this.options[this.selectedIndex].value)">
<option value></option>
<option value="AAAAAA">AAAAAA</option>
<option value="BBBBBB">BBBBBB</option>
<option value="CCCCCC">CCCCCC</option>
<option value="DDDDDD">DDDDDD</option>
<option value="EEEEEE">EEEEEE</option>
</select>
0
 
lil_puffballCommented:
I believe it is impossible to do this in an alert, however you can have a pop-up window that looks like an alert and use that.
0
 
cubrovicCommented:
What are you want?
To have a dropdown list in alert message box ?
If so that's impossible.
0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
lil_puffballCommented:
for example...

window.open("alert.htm","newwin","height=100,width=300",toolbar="no",menubar="no",scrollbars="no",resizable="no",location="no",directories="no",statud="no");

And in alert.htm, make the background gray, write anything you want and add a button like this...

<input type="button" onClick="self.close()">OK</a>

which will make it just like an alert.
0
 
luckydog374Author Commented:
jonnal,

I'm trying to have the dropdown list within the alert box.
0
 
lil_puffballCommented:
oh, in your window.open you should also add something like left="150",top="150" so it centers.
0
 
jonnalCommented:
well then go with lil_puffballs code
0
 
jonnalCommented:
hi again try this in IE (6 probably)

<HEAD>
<TITLE>Creating a Link and Retrieve the URL</TITLE>
<LINK REL="stylesheet" HREF="samples.css" TYPE="text/css"/>
</HEAD>
<BODY>
<H1 unselectable="on">Creating a Link and Retrieve the URL</H1>
<script>
function AddLink()
{//identify selected text
var sText = document.selection.createRange();
if (sText.text!=""){
  //create link
  document.execCommand("CreateLink");
  //replace text with URL
  if (sText.parentElement().tagName == "A"){
    sText.parentElement().innerText=sText.parentElement().href;
    document.execCommand("ForeColor","false","#FF0033");
  }
}
else{
    alert("Please select some blue text!");
}
}
</script>

<P unselectable="on">Select any portion of the following blue text, such as "My favorite Web site". Click the button to turn the selected text into a link.  The text will be changed to the URL that you specify.</P><P style="color=#3366CC">My favorite Web site is worth clicking on. Don't forget to check out my favorite music group!</P>
<BUTTON onclick="AddLink()" unselectable="on">Click to add link</BUTTON>
<P class="viewsource" unselectable="on">To view the source code, right-click this page and choose View Source from the shortcut menu.</P>

</A>
</BODY>
</HTML>
0
 
lil_puffballCommented:
uh, jonnal? I'm not sure but I think you posted in the wrong place...
0
 
lil_puffballCommented:
oh, ok never mind, I see...when you click on the button there's a drop-down on the pop-up..I was just wondering what the other stuff was doing there.

Well, that's very cool, I didn't know you could do that with pop-ups...:)
0
 
ahosangCommented:
Why dropdown in an 'alert-type' box?? What do you want when something is selected from the dropdown? And so on. What are you trying to implement?
0
 
luckydog374Author Commented:
lil puffball,

I agree - that's a cool usage of alert boxes, however it's not exactly what I need.

Currently I have an alert box with a field that the user types in text.  Instead, I'd prefer to limit the data by having dropdown list with limited options that I specify.

If this isn't possible with JavaScript, would it work with VBScript?  
0
 
lil_puffballCommented:
jonnal,
How exactly does that work? I have narrowed it down to see that

document.execCommand("CreateLink");

is really what is doing the alert box. What exactly is execCommand? (I am not very good at javascript so please forgive me if this is a really stupid question! :) )

0
 
lil_puffballCommented:
oh, also I was wondering what effect "unselectable=on" has?
0
 
jonnalCommented:
hi lil

dont really know
you seem to get alot from not to much code
its a ms dhtml thing !!

here is a microsoft artical on it

http://msdn.microsoft.com/library/default.asp?url=/workshop/author/dhtml/reference/commandids.asp
0
 
lil_puffballCommented:
luckydog it's been a long time, just showing you an example. This is very simple but you can jazz it up to look more like an alert.

<script>
var str="<center><body bgcolor=eaeadd><form>Please Select: <select>";
str+="<option>Opt1<option>Opt2<option>Opt3<option>Opt4</select>";
str+="<p><input type=button style='font-size:12px' value='     OK     ' onClick='self.close();'></form></body>";
var win=false;
function openwin(){
win=window.open("","","height=70,width=200,left=200,top=200");
win.document.write(str);
alert('s')
}
</script>

<body onFocus="if(win&&!win.closed){win.focus();}">
<a href="#" onClick="openwin()">asd</a>
<input type=text onKeyUp="document.bgColor=this.value">
0
 
jaysolomonCommented:
No comment has been added lately, so it's time to clean up this TA.
I will leave the following recommendation for this question in the Cleanup topic area:

Split: jonnal {http:#8068101} & lil_puffball {http:#8323596}

Please leave any comments here within the next seven days.
PLEASE DO NOT ACCEPT THIS COMMENT AS AN ANSWER!

jAy
EE Cleanup Volunteer
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 8
  • 4
  • 2
  • +3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now