aspose file tools*
The moose likes HTML, CSS and JavaScript and the fly likes add an element to select box Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Engineering » HTML, CSS and JavaScript
Bookmark "add an element to select box" Watch "add an element to select box" New topic
Author

add an element to select box

Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I have a jsp which has a select box and a button...

On click of that button I pop up a window(with a text field,OK,cancel buttons) which allows a user to enter a value in the text filed it contains !!!

Now on OK,the window should dissapear(not done) and the value should be set to the existing select box which already has values!!!


ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
write mehtod onclick of Ok button

use DHTML to set the value

var obj --refers your jsp
like top.opener.Document
var objName = obj.getElementById(ID attribute of your selecttag);

var opt = obj.createElement("option");
opt.appendChild(obj.createTextNode("<%=sValue%>"));
opt.value="<%=sValue%>";
objName.appendChild(opt);
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Actualy that select is in a jsp...and this window I wrote in html.So on button click in jsp,I am popping the window saved as a html file .Now in this html file on OK button click I should write a JS .But how to get select tag attribute present in jsp in this JS function saved as .html?select tag and the JS function are in 2 different places!! I am confused here.
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
i think you need to transer control to another jsp on onclick event of Ok button which will be hidden and do the processing in that jsp

just try
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
How does one transfer control to another jsp?? It would be great If I can have one example...
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
var url = "sample.jsp?<%=paramBuff.toString()%>";

document.location.href=url;
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
I am still new to Javascript hence the strutggles.

?<%=paramBuff.toString()%>";


could you just explain this?what should come here and what the one you have written does?
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61239
    
  66

Pradeep Adibatla wrote:I am still new to Javascript hence the strutggles.

?<%=paramBuff.toString()%>";


could you just explain this?what should come here and what the one you have written does?

That is JSP (and bad JSP at that) and has nothing to do with JavaScript.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
ravindra patil
Ranch Hand

Joined: Sep 01, 2006
Posts: 230
its scriplets defined in java , i am appending it to that jsp so i can get that parameters in that jsp using request.getParameter();

Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61239
    
  66

ravindra patil wrote: its scriplets defined in java , i am appending it to that jsp so i can get that parameters in that jsp using request.getParameter();

This is an HTML forum -- please refrain from posting JSP code. There is no need to use JSP to solve this issue.
Pradeep Adibatla
Ranch Hand

Joined: Oct 27, 2009
Posts: 336
Bear,could you tell how it should be done using JS...
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61239
    
  66

Sorry but I am still unsure what you are trying to accomplish. Adding an option to a select is fairly easy using the select element's add() method, but in your description you start talking about other windows and links and such without explanation which just confuses the whole issue.

Perhaps you can state, clearly and succinctly, what it is you are trying to do.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: add an element to select box