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!

onClick and re-direct at the same time

Status
Not open for further replies.

gchen

Programmer
Nov 14, 2002
174
US
Hi,

i need some tips from you gurus ;) thanks a lot!

how can i envoke a javascript function i.e. check_data(), which is to check if certain form field have been filled by visitor,

ALONG WITH

a re-direction function using location="
currently I use onSubmit="return check_data();" but when visitor click submit, the check_data() is called upon and working fine, but i don't know how and where to envoke another javascript to re-direct visitor to my thank you page.

Any suggestion?

Help PLEASSSSSSSSEEEE !!!!!
 

Do you want to check and redirect, or do you want to check and submit a form? The two are very different, albeit with the same end result.

Dan

 
Dan,

Thanks for coming to help.

I need do achieve -

1. check form data
2. if data is okay, proceed the form
3. then redirect to another page

All in one shot.

Is it possible?

Thanks!

Gary
 
The page you submit to should do the checking of the data and the redirect.

Lee
 
Lee,

this is not quite like that...

the server side actually does just one thing after the form is submitted and that is to invoke download by "Location: ...";

so i have to build some intelligence at client side, browser, to do form check, submit form and self-redirect after the submission. Can't rely on server script to do it.

Any other suggestion?

Gary
 
gchen,

How about/what's wrong with using a modeless window.open() to do that? Or maybe I miss something. Something like this, for instance.
[tt]
<form name="formtest" action==" method="post">
username:&nbsp;<input type="text" name="usr" /><br/>
password:&nbsp;<input type="password" name="psswrd" /><br />
<input type="submit" onclick="return check_data();" /><br />
</form>
[/tt]
and then the function.
[tt]
function check_data() {
if (document.formtest.usr.value=="") {
alert("You have to fill in username.");
document.formtest.usr.focus();
return false
} else {
window.open (" return true;
}
}
[/tt]
(Add features for window.open() is so desired.)

regards - tsuji
 

I think that tsuji is on the right track, assuming you cannot do the redirection server-side.

If you want to guarantee the form is submitted, you cannot redirect the page (as the form will not submit). Aside from using frames or iframes, a popup window would be the only other choice, IMHO.

Dan

 
Though i would like to have a solution to self re-direct to a thank you page instead of a pop-up window. i think i can live with it. Only thing is pop-up blocker is so popular these days.... :(

Thank you all!
 
gchen wrote:
>Though i would like to have a solution to self re-direct to a thank you page instead of a pop-up window. i think i can live with it...

Guess we don't know what you want. Why must javascript get involved in this case? Isn't it the action attribute is there for? If you must have some client-side risk to take, you can spare the action attribute and set it when onclick with document.formname.action set to thankyoupage... Guess I really don't understand after all.

- tsuji
 
Hi,
location='the url here'
That's for redirect exaple can call on function or just in onClick..

<input name="Button" type="button" class="Button" value="Add Invoice" onClick="location='SelectPOLineItem.html'">
Goes to the page SelectPOLineItem.html....

Snot.
 
I am trying to have a Print Button that will print only part of the web page. I have searched several sites and found

==========================================================
You can also easily control what parts of your page print out by adding a special stylesheet that will be used for printing to the head section of your page like this:

<link rel="stylesheet" href="print.css"
type="text/css" media="print" />
The print.css file should contain the following:

body {visibility:hidden;}
.print {visibility:visible;}

Now all you need to do is to assign class="print" to whatever parts of your web page that you want to have print out. Anything on the page not assigned to this class will not print.

=========================================================

So I created the css and imbedded the code --

but I am unable to get the "onClick" statement correct to print only the portion identified in the class=Print statement.

Can you tell me what the onClick command should be to only print the class=print portion of the web?

I have tried

<form><input type="button" value=" Print "
onclick="window.print();return false;" /></form>

and

<form><input type="button" value=" Print this page "
<a href="#" onclick="window.print();return false;">
</form>

Thanks for your help



 

The onlick statement is fine - you do nothing special with the JS (that's the whole idea of having the media identifier with style).

Suggest asking in the HTML / CSS forum to make sure you've correctly applied the CSS.

Hope this helps,
Dan


The answers you get are only as good as the information you give!

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top