Click to See Complete Forum and Search --> : confirm box with anchor and spinner


matthewst
05-08-2007, 01:04 PM
My php page has a spinner on it:
<script>
function spin( obj )
{
var spinner = document.getElementById( obj );
var spinner_content = document.getElementById( obj+"_body" );
if ( spinner_content.style.display == 'block' ) // this line
{
spinner.innerHTML = '+';
spinner_content.style.display = 'none'; // this line
spinner_content.style.height = '0px';
spinner_content.style.margin = '0px';
}
else
{
spinner.innerHTML = '-';
spinner_content.style.display = 'block'; // this line
spinner_content.style.height = 'auto';
spinner_content.style.margin = '20px 0px 20px 50px';
}
}
</script>

I have an anchor at start_spinner:
<?php start_spinner( 'up_order_spin', "Table Order Form" );?>
<a name="tableorderform"></a>
<table align="center">

When my users click submit...:
<input type="submit" name="submit" class="formTextbox" value="Submit" onclick="go_there()">

...a box pops up that asks if they want to fill out an order form...
<SCRIPT language="JavaScript">
<!--
function go_there()
{
var where_to= confirm("Did you fill out the Table Order Form?");
if (where_to== false)
{
window.location="http://www.mysite.net/mypage2.php#tableorderform";
}
else
{
window.location="http://www.mysite.net/projects.php";
}
}
//-->
</SCRIPT>

...no matter what they click they are taken to projects.php.

What I need is: If they click "OK" they go to projects.php, but if they click "Cancel" then stay at mypage2.php and the spinner opens for them.

matthewst
05-08-2007, 02:02 PM
belongs in a javascript fourm, sorry about that

cgraz
05-08-2007, 04:33 PM
no problem. Moved it for you.

bradgrafelman
05-09-2007, 11:30 AM
The problem probably lies in the fact that this is a submit button, so the browser attempts to switch locations, but then the form forces the browser to submit the data to the address you specified in the 'action' attribute.

Try doing something like this for your Javascript: <script type="text/javascript">
<!--
function go_there()
{
var where_to= confirm("Did you fill out the Table Order Form?");
if (where_to== false)
{
window.location="http://www.mysite.net/mypage2.php#tableorderform";
}
else
{
window.location="http://www.mysite.net/projects.php";
}
return false;
}
//-->
</script>and then use this for your submit button: <input type="submit" name="submit" class="formTextbox" value="Submit" onclick="return go_there()">What that basically does is cancels the submit button's action of submitting the form, thus the browser won't be interrupted form loading the new location based on the confirm() box.