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

confirmation with spinner and anchor

Status
Not open for further replies.

matthewst

IS-IT--Management
May 1, 2007
25
0
0
US
My php page has a spinner on it:
Code:
<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:
Code:
<?php start_spinner( 'up_order_spin', "Table Order Form" );?>
										<a name="tableorderform"></a>
										<table align="center">

When my users click submit...:
Code:
<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...
Code:
<SCRIPT language="JavaScript">
<!--
function go_there()
{
 var where_to= confirm("Did you fill out the Table Order Form?");
 if (where_to== false)
 {
   window.location="[URL unfurl="true"]http://www.mysite.net/mypage2.php#tableorderform";[/URL]
 }
 else
 {
  window.location="[URL unfurl="true"]http://www.mysite.net/projects.php";[/URL]
  }
}
//-->
</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.
 
It may be the submit button that is taking them to the projects.php page. Clicking a submit button submits the form to the form action url. this may happen regardless of the onclick event handler. The event handler may run and show the confirm dialog and request the appropriate url. And then the browser will complete the submit action and request the form action url. Just a thought.

so use a button instead of a submit button and see what happens.

Of course if you actually wish to submit the form data then you would override the form action in the event handler and use javascript to submit the form.

Code:
<input type="button" name="gothere" class="formTextbox" value="Submit" onclick="go_there()">
and
Code:
<SCRIPT language="JavaScript">
<!--
function go_there()
{
 var where_to= confirm("Did you fill out the Table Order Form?");
 if (where_to== false)
 {
   document.forms[0].action = "[URL unfurl="true"]http://www.mysite.net/mypage2.php#tableorderform";[/URL]
 }
 else
 {
   document.forms[0].action = "[URL unfurl="true"]http://www.mysite.net/projects.php";[/URL]
  }
}
document.forms[0].submit();
//-->
</SCRIPT>
Note that the button field is not named "submit". That avoids another naming conflict with the method named "submit".
 
I must be doing something wrong. No matter which button (on the popup) I click I'm not directed to either projects.php or #tableorderform.
 
It would seem so.

I checked my code in a mockup and "it works for me".

So.

Well actually, there was one little mistake in my code. The document.forms[0].submit() statement should be inside the function. Otherwise the page just loops.
Code:
<SCRIPT language="JavaScript">
<!--
function go_there()
{
 var where_to= confirm("Did you fill out the Table Order Form?");
 if (where_to== false)
 {
   document.forms[0].action = "[URL unfurl="true"]http://www.mysite.net/mypage2.php#tableorderform";[/URL]
 }
 else
 {
   document.forms[0].action = "[URL unfurl="true"]http://www.mysite.net/projects.php";[/URL]
  }
document.forms[0].submit();
[COLOR=red]}[/color]

//-->
</SCRIPT>

I have no idea what a spinner is.

Is it possible that in this line of your code
Code:
<?php start_spinner( 'up_order_spin', "Table Order Form" );?>
                                        <a name="tableorderform"></a>

that the string "Table Order Form" needs to match exactly the name of the anchor tag, "tableorderform"?

NB, getElementById("tableorderform") only works because IE assumes that names and IDs have the same value. It is not correct HTML if you intend to write the innerHTML in the anchor tag. It should read
Code:
<a id="tableorderform"></a>

Are you actually using the input button tag in a form?


Just some ideas. Also you might look for Javascript errors.
 
A spinner (well the one I'm refering to) is...a plus sign on your page, when you click it the page expands to reveal "hidden" content. You can then click the minus (plus turns into minus when expanded) sign to "hide" the extra content. The problem I have is I can't get the page to "auto-expand" when my users click cancel in the popup.
 
My anchor is in the part of the page that is "hidden".
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top