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 Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Combobox with value validation for open window

Status
Not open for further replies.

RicardoPereira

Programmer
Jun 3, 2003
255
PT
Hi,

I want to have a combobox that open automatically a new window if i select a specific value.

Here is the ideia. I have this html code:

<Select name="Test" class="formstyleShort">
<OPTION value='' selected>Blank</option>
<OPTION value='R'>CNN</option>
<OPTION value='I'>BBC</option>
&nbsp;
<input type='button' value='Go!'>

I only want to open a new window if i select the "BBC" option. Otherwise, the option is selected ("Blank" or "CNN") without open a new window.

It´s possible ?

Thanks
 
will the new window be blank?

Code:
<select name="Test" class="formstyleShort" [red]onchange="if (this.selectedIndex==2){window.open("about:blank","w","");}"[/red]>



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Hi change the code but, doesn´t work :(
I want to open a test page (test.htm)

Code:
<select name="Test" class="formstyleShort" onchange="if (this.selectedIndex==2){window.open("test.htm","w","");}">
<OPTION value='' selected></option>
<OPTION value='R'>CNN</option>
<OPTION value='I'>BBC</option>
</form>
 
sorry, i'm a fool. try this:

Code:
<select name="Test" class="formstyleShort" onchange="if (this.selectedIndex==2){window.open([red]'[/red]test.htm[red]'[/red],[red]'[/red]w[red]'[/red],[red]'[/red][red]'[/red]);}">



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Sorry, one more question.

And if i want to have a link that open the new page only if the value 'CNN' is selected ?
 
you have two options. the first is to put the url in the valu e of the option, and then do something like this:

Code:
<select ... onchange="if (this.selectedIndex>0) window.open(this.options[this.selectedIndex].value,'w','');">
  <option value=""></option>
  <option value="[URL unfurl="true"]www.google.com">Google</option>[/URL]
  <option value="[URL unfurl="true"]www.yahoo.com">Yahoo!</option>[/URL]
</select>

or the other is to hard-code the urls into a function:

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

function doUrl(s) {
    switch (s.selectedIndex) {
        case 1:
            var w = window.open("[URL unfurl="true"]http://www.google.com/",[/URL] "w", "");
            break;
        case 2:
            var w = window.open("[URL unfurl="true"]http://www.yahoo.com/",[/URL] "w", "");
            break;
        default:
            alert("No window will be opened for this selection");
            break;
    }
}

//--></script>

.
.
.
<select ... onchange="doUrl(this);">
  <option value=""></option>
  <option value="R">CNN</option>
  <option value="I">BBC</option>
</select>



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
I was asking if it's possible to open the url not automatically. Using some like "<input type="button" name="test" value="Go!"
onClick="gotoURL()">".
But the new window open only if the value selected is the "BBC". Otherwise just select.

It's possible ?
 
yes it is. take what you have in the onchange event and move it to the onclick event of the button. replace "this" with "this.form.elements['Test']".



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
with this code it doesn't work :(

Code:
<select name="RecInc" class="formstyleShort">
<OPTION value='' selected></option>
<OPTION value='R'>Reclamação</option>
<OPTION value='I'>Incidência</option>
</form>
<input type="button" name="test" value="Go!" onclick="if (this.form.elements['RecInc'].selectedIndex==1){window.open('about:blank','newwindow','width=200,height=100%');}">
 
Even if i put the </select> i got an error of "Object required"

Code:
<select name="RecInc" class="formstyleShort">
<OPTION value='' selected></option>
<OPTION value='R'>Reclamação</option>
<OPTION value='I'>Incidência</option>
<input type="button" name="test" value="Go!" onclick="if (this.form.elements['RecInc'].selectedIndex==1){window.open('about:blank','newwindow','width=200,height=100%');}">
</select>
 
i assumed you had some basic understanding of HTML. this worked perfectly for me:

Code:
<form name="f">
<select name="RecInc" class="formstyleShort">
    <OPTION value='' selected></option>
    <OPTION value='R'>Reclamação</option>
    <OPTION value='I'>Incidência</option>
</select>
<input type="button" name="test" value="Go!" onclick="if (this.form.elements['RecInc'].selectedIndex==1){window.open('about:blank','newwindow','width=200,height=100%');}">
</form>


you should try to make some effort to learn things yourself - it can't always be expected that people on here will do everything for you.



*cLFlaVA
----------------------------
[tt]( <P> <B>)13 * (<P> <.</B>)[/tt]

[URL unfurl="true"]http://www.coryarthus.com/[/url]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top