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

Using Window.Open with dynamic Form button

Status
Not open for further replies.

birdycarolyn

Technical User
Apr 9, 2002
8
US
Hello Experts,

I'm very new to Javascript and was hoping someone could help me out. I have 2 buttons on a form that return results from a database and each Action and Target is set dynamically by the following code:

Code:
<INPUT type=&quot;button&quot; value=&quot;View Results&quot; name=button1 onclick=&quot;return OnButton1();&quot;>  
<INPUT type=&quot;button&quot; value=&quot;Printer Friendly&quot; name=button2 onclick=&quot;return OnButton2();&quot;>

function OnButton1()
{	document.Form1.action = &quot;results_vr1.asp&quot;;
	document.Form1.target = &quot;_self&quot;; 
	document.Form1.submit();			
	return true;
}

function OnButton2()
{	document.Form1.action = &quot;results_vr2.asp&quot;
	document.Form1.target = &quot;_blank&quot;;	
	document.Form1.submit();			
	return true;
}

In function OnButton2(), the target is set to _blank which is what I want, but at the same time I would like to incorporate the Window.Open command to control how the window opens and it's width and height:
Code:
window.open(&quot;results_vr2.asp&quot;, &quot;newwindow&quot;, &quot;resizeable=yes,scrollbars=yes,toolbar=yes,menubar=yes,width=750,height=550,innerWidth=750,innerHeight=550,left=0,top=0&quot;);
Does anyone know how I can incorporate the 2? As a bonus, does anyone know how I can keep sending my data to the opened blank window so that I don't have many windows opened every time they choose the button (in other words, keep the focus on that window while refreshing the data table within it)?

I hope I am being clear and appreciate any help! Carolyn

 
Hello,

I'm not quite sure I understand what you mean, but it migth be an option to call the asp-page with:
Code:
function OnButton2()
{    document.Form1.action = &quot;results_vr2.asp?var1=test1&var2=test1&var3=test1&quot;
    document.Form1.target = &quot;_blank&quot;;    
    document.Form1.submit();            
    return true;
}

where var1 / var2 / var3 can be replaced with your variables out of the form.

in the results_vr2.asp page you will have to add a javascript that gets the information out of the href:
It will look something like this:
Code:
if (window.location.search.substring(1).length > 4) {
var variables = window.location.search.substring(1);
//split the string at every &quot;&&quot;
var variables_splitted = variables.split(&quot;&&quot;);
//with a loop get the rest into an assiociative array
for (var loop = 0; loop < variables_splitted.length; loop++) {
var property_value_pair = variables_splitted[loop];
var temp_array = property_value_pair.split(&quot;:&quot;);
var property = temp_array[0];
var value = temp_array[1];
get[property] = value;
}
}
else {
//put something to do else
}

I'm not sure the &quot;get[property] = value;&quot; line is working >> having some trouble with it, but it is only a guideline

Wouter
 
btw I forgot something:

set the variables with:
Code:
var var1 = get[&quot;var1&quot;];
var var2 = get[&quot;var2&quot;];
 
Thanks WouterP for your help, but I found a simpler way (at least for me to understand!) to make it work. Thanks again for your time!

<form name=&quot;Form1&quot; method=&quot;post&quot; action=&quot;&quot;>
<input type=&quot;button&quot; name=&quot;bu1&quot; value=&quot;button 1&quot; onClick=&quot;return OnButton1();&quot;>
<input type=&quot;button&quot; name=&quot;but2&quot; value=&quot;button 2&quot; onClick=&quot;return OnButton2();&quot;>
</form>
<script>
function OnButton1()
{ document.Form1.action = &quot;yourReceiver.jsp&quot;;
document.Form1.target = &quot;_self&quot;;
document.Form1.submit();
return true;
}

function OnButton2(){
myWindow = window.open('initialBlank.html','myWindow','height=400,width=300,scrollbars,left=100,top=100');
document.Form1.action = 'yourReceiver.jsp';
document.Form1.target = 'myWindow';
document.Form1.submit();
myWindow.focus();
return false;
}
</script>
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top