Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations TouchToneTommy on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Getting values from a select box in a new page

Status
Not open for further replies.

countdrak

Programmer
Jun 20, 2003
358
US
I have a select box and a link. Something like this.

Code:
<select name="select" size="10">
 <option value= "116">X</option>
 <option value= "117">Y</option>
 <option value= "118">A</option>
 <option value= "119">B</option>
 <option value= "120">C</option>
</select>

<a href ="javascript:document.form1.submit();CreateWindow('[URL unfurl="true"]http://127.0.0.1/edit.cfm?ID=#Form.Select#')"[/URL] > Edit </a>

The user picks an option from the select box and then clicks on "Edit". I open a NEW window using a custom javascript function called CreateWindow and pass the value of the option through my url as shown. But the first time I do this I always get an empty string in the new window! The page first opens my link and then submits the page, but I want it to submit the page first and then open the link, so I can get the value of the option. Does anyone know a work around or a diffirent way of doing this?
 
Try this:

Code:
<!-- ... -->
<script type="text/javascript">
<!--

function startForm()
{
  var sel = document.forms['form1'].elements['select'];
  var id = sel.options[sel.selectedIndex].value;
  window.open("[URL unfurl="true"]http://127.0.0.1/edit.cfm?ID="[/URL] + id,"newwin");
}

// end hide -->
</script>
<!-- ... -->
<a href="javascript:startForm()">Edit</a>
<!-- ... -->

Does CreateWindow do anyting other than open a window with the submitted URL, replacing the stuff between "#"s (with certain attributes)? If not, this should work.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Well this is what create window looks like...
Code:
function CreateWindow(x) 
    {
    Swin = window.open(x,"Attachfile","toolbar=0,location=0,directories=0,status=0,menubar=0,scrollbars=yes,resizable=yes,width=375,height=600,top=0,left=0");
}
What does "newwin" do? Is is a variable or something?
 
newwin" does the same thing that "Attachfile" does in CreateWindow: it is the name of the window.

So once I create this window, I can open Google in it by clicking a link like this:
<a href=" target="newwin">Google in new window</a>.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Does it work?

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
options is not null or not an object"! arggghh..Does not open a new window, javascript throws an error.
 
Try changing the select's name to something other than "select", i.e. "select1".

Change the function:

var sel = document.forms['form1'].elements['select'];

should be

var sel = document.forms['form1'].elements['[red]newName[/red]'];
Fill in "newName" with the name of your select.
Also, make sure your form is named "form1" or modify accordingly.

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Works great ..Thanks a million. Doesnt like the name select.
 
Good!

Generally, Javascript has problems with names that are the same as tags (<form name="form">, <div name="div">).

--Chessbot

"So it goes."
Kurt Vonnegut, Slaughterhouse Five
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top