frijole Posted April 21, 2008 Share Posted April 21, 2008 I have a homework question where I am supposed to prompt for user's name, sex, and some other things. Most of the answers will be strings, like the users name. But, is there a way to give 2 options to choose from? Thanks for reading. Quote Link to comment Share on other sites More sharing options...
optikalefx Posted April 21, 2008 Share Posted April 21, 2008 to tell you the truth, your better off with a div overlay than a prompt dialog. I know this probably changes everything for you, but I know you can do ANYTHING with the div. just do something like var newDiv = document.createElement('DIV'); newDiv.width = 300; newDiv.height = 300; newDiv.position = "absolute"; newDiv.top = document.body.clientHeight/2; // horizontally center newDiv.left = document.body.clientWidth/2; // vertically center newDiv.innerHTML = "<form action='' method=''><select name='info'><item name='male'>male</item><item name='female'>female</item></select></form> document.body.appendChild(newDiv); i didnt test this, so it may not be 100% but thats the main idea so that will put a div with custom html inside of it on the page. And then you can add more to that html that would call a function which would make the div go away document.body.removeChild(newDiv); oh and if the prompt is onLoad you can add to the body <body onload="placeDiv();"> and just have that run the code above, or similar Quote Link to comment Share on other sites More sharing options...
frijole Posted April 21, 2008 Author Share Posted April 21, 2008 Thanks for the thorough answer. For my specific case I need to somehow prompt if they are male or female. I would prefer not to just have them type it in because I would have to verify the data that way. Is there any way to have a prompt that gives 2 options to choose from? All JavaScript too? Thanks for the help. Quote Link to comment Share on other sites More sharing options...
optikalefx Posted April 22, 2008 Share Posted April 22, 2008 so are you saying the DIV prompt wont work? And in any case to get the data without typage is to use a select box (ist a drop down) i gave the sample code for that in my earlier post, in the .innerHTML part Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.