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

submit button(image field) spawns new window

Status
Not open for further replies.

btish

Programmer
Aug 7, 2001
23
US
btish (Visitor) Apr 4, 2001
Hello guys,
I have a submit button in one of my forms that is spawning a new window every time I try and calculate my javascript function. The button is actually an image field that acts like a typical button, but again it spawns a new page.

I DON"T want it to spawn a new page. Any ideas on how to solve this?
The code is below:

<input type=&quot;image&quot; name=&quot;submit&quot; onClick=&quot;calculate()&quot; src=&quot;/roi_calculator/slices/images/input_interface_11.gif&quot; width=&quot;136&quot; height=&quot;35&quot;>

Thanks in advance for any help.
Btish
 
What is the action and target of your form? Maybe it's defaulting to target=&quot;_blank&quot;. Does it open anew page - or new window? Give us the rest of your form code if it's not too big ;-)
b2 - benbiddington@surf4nix.com
 

It opens a new page, not a new window. I just want it to calculate the form numbers. I tried putting in
target=&quot;_self&quot; and that didn't work. Soooo, here's the code for the total form. Thanks again for any help:

<form name=&quot;calculator&quot;>
<table border=0 cellpadding=0 cellspacing=0>
<tr>
<td colspan=4><img src=&quot;/roi_calculator/slices/header-copy.gif&quot; width=&quot;364&quot; height=&quot;138&quot;></td>
</tr>
<tr>
<td colspan=4><img src=&quot;roi_calculator/slices/images/images/input_interface_01.gif&quot; width=&quot;364&quot; height=&quot;56&quot;></td>
</tr>
<tr>
<td bgcolor=&quot;#990000&quot; valign=&quot;top&quot; rowspan=&quot;3&quot; width=&quot;298&quot;>
<img src=&quot;/roi_calculator/slices/images/input_interface_02.gif&quot; width=&quot;284&quot; height=&quot;194&quot;>
</td>
<td valign=&quot;middle&quot; align=&quot;center&quot; bgcolor=&quot;#990000&quot; width=&quot;66&quot; height=&quot;66&quot;>
<input type=&quot;text&quot; name=&quot;csrs&quot; size=&quot;7&quot; onBlur=&quot;calculate()&quot; onFocus=&quot;calculate()&quot; value=&quot;6&quot;>
</td>
<td align=&quot;right&quot; valign=&quot;top&quot; rowspan=&quot;4&quot; width=&quot;1&quot;>&nbsp;</td>
<td valign=&quot;top&quot; rowspan=&quot;4&quot; width=&quot;1&quot;>&nbsp;
<tr>
<td valign=&quot;middle&quot; align=&quot;center&quot; bgcolor=&quot;#990000&quot; width=&quot;66&quot; height=&quot;64&quot;>
<input type=&quot;text&quot; name=&quot;hrsperweek&quot; size=&quot;7&quot; onBlur=&quot;calculate()&quot; onFocus=&quot;calculate()&quot; value=&quot;55&quot;>
</td>
<tr>
<td valign=&quot;middle&quot; align=&quot;center&quot; bgcolor=&quot;#990000&quot; width=&quot;66&quot; height=&quot;64&quot;>
<input type=&quot;text&quot; name=&quot;salary&quot; size=&quot;7&quot; onBlur=&quot;calculate()&quot; onFocus=&quot;calculate()&quot; value=&quot;16&quot;>
</td>
<tr>
<td height=&quot;28&quot; bgcolor=&quot;#990000&quot; width=&quot;298&quot;> <img src=&quot;/roi_calculator/slices/images/input_interface_12.gif&quot; width=&quot;146&quot; height=&quot;35&quot;>
<input type=&quot;image&quot; onclick=&quot;calculate()&quot; name=&quot;submit&quot; src=&quot;/roi_calculator/slices/images/input_interface_11.gif&quot; width=&quot;136&quot; height=&quot;35&quot;>
</td>
<td align=&quot;center&quot; valign=&quot;middle&quot; bgcolor=&quot;#990000&quot; width=&quot;66&quot; height=&quot;28&quot;>
<input type=&quot;text&quot; name=&quot;savings&quot; size=&quot;8&quot;>
</td>
</table>
<p align=&quot;left&quot;>
<script language=&quot;JavaScript&quot; type=&quot;text/javascript&quot;>

function calculate() {
//form variables
var csrs = document.calculator.csrs.value;
var hours = document.calculator.hrsperweek.value;
var salary = document.calculator.salary.value;
var savings = document.calculator.savings.value;

//constants or assumptions
var log_present = .68;
var log_ineto = .77;
var issues_present = .8;
var issues_ineto = .9;

//intermediate calculations - efficiency
var increased_hrs = (log_ineto - log_present)/log_present
var decreased_idle = (issues_ineto - issues_present)/issues_present
var efficiency = .25 //increased_hrs + decreased_idle???

//calculations from top red square
var totalhoursperweek = csrs*hours
var customerhrs = totalhoursperweek*log_present*issues_present
var customertimeincrease = customerhrs/csrs
var hrsavailable = customerhrs*(1+increased_hrs)*(1+decreased_idle)
var effectivehrs = hrsavailable*(1+efficiency)
var newhrs = effectivehrs/csrs
var agents_needed = customerhrs/newhrs
var sav_per_week = (csrs-agents_needed)*hours*salary
var sav_per_month = sav_per_week/5*22

//calculations from bottom red square
var minutes = customerhrs/5*22*60
var ccu = minutes*.15
var net = sav_per_month - ccu


//write the final answer into the last form field
document.calculator.savings.value = '$'+round(net);
}


function round(x) {
return Math.round(x);
}



</script></form>
Thanks banger!
 
O.K. I'll have a look ;)
b2 - benbiddington@surf4nix.com
 
thanks for looking bangers! Maybe it has something to do with the type of input when I just use the regular &quot;button&quot; type of input(instead of an image field) the calculator works fine and doesn't spawn a new page. But when I try and add a source image and make the image a submit button, it creates the new page.....

I hope I've explained this OK.
I don't think I will have to be forced to use the regular submit button because I think I've seen it done before?
Thanks for looking at the code bangers.
B
 
Apologies for taking so long, internal server errors.

It turns out that these automatically submit the form - along with the coords of the click - so really it is a submit button I guess
(check the url in the location bar out when you click the button - it will contain all the form field values and x,y values.)


Anyway why don't you try just using an image - surrounded in a link if you want NS4.x compliance - then you can do exactly the same things wothout these additional hassles.

<a href=&quot;javascript:void(0)&quot; onClick=&quot;calculate(calculator)&quot;>
<img src=&quot;/roi_calculator/slices/images/input_interface_11.gif&quot; width=&quot;136&quot; height=&quot;35&quot;>
</a>

Do you think this kind of thing will be suitable? Check out this page at MSDN (the best site)

;-)
b2 - benbiddington@surf4nix.com
 
You rock bangers!!!!! It worked beautifully. Thank you.
May your server errors be few.
Brandon
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top