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

Can a form's action be a function?

Status
Not open for further replies.

pugs421

Technical User
Joined
Nov 25, 2002
Messages
114
Location
US
I was looking at someone elses code in javascript and I see that the form's action is a function.
ex. <FORM METHOD='POST' ACTION=&quot;javascript:LogIt('M-A-T-R-I-X','20030809')&quot;> (LogIt being the function). Can I do that in php? whats the propper syntax?
 
What do you mean it wont work, I pulled that from a working site. Actually my company's.
 
can we have the entire code?

and fraley99 it might work if the function LogIt returns a value.

Known is handfull, Unknown is worldfull
 
A javascript function is valled on an event.
SO probably u want to call the function on onSubmit() event of a form.
ie
Code:
<FORM METHOD='POST' ACTION=&quot;&quot; onSubmit=&quot;javascript:LogIt('M-A-T-R-I-X','20030809')&quot;>
if u want to handle that using PHP, u can incorporate the javascript code in PHP.
ie
Code:
<FORM METHOD='POST' ACTION=&quot;action.php&quot;>
..
in action.php u can incorporate the function like
echo &quot;<script language=javascript>&quot; ;
echo &quot;function LogIt('M-A-T-R-I-X','20030809'){
....
&quot; ;
[/code]
Note however that u cant access Javascript variables in php, but vice a versa is possible as PHP is executed at server side ie before javascript gets ececuted on client side.





--------------------------------------------------------------------------
I never set a goal because u never know whats going to happen tommorow.
 
<script language='Javascript'>
<!--
function LogIt(pVch, pDate)
{
var cLoc;
var pVB = document.TheViewer.VIEWER.value;
if (pVB=='') {
alert('Please Enter Your Name');
}
else
{
cLoc = ' + pVch + '&viewedby=' + pVB + '&date=' + pDate;
window.open( cLoc, 'LogitStatus', 'toobar=no,height=200,width=500,directories=no,status=no,scrollbars=yes,resize=no,menubar=no' );
}
}//-->
</script>


<FORM METHOD='POST' ACTION=&quot;javascript:LogIt('M_A_D_O_N_N_A','20030809')&quot;><INPUT TYPE='hidden' NAME='SCREENNAME' VALUE='M_A_D_O_N_N_A'><INPUT TYPE='hidden' NAME='DATE' VALUE='20030809'><INPUT TYPE='submit' VALUE='Log as Viewed'></FORM>
 
I asked this question as an indirect way of figuring out my real question. I just didn't want to pose a 'How do they do this?' question. But here it is anyway if anyone could point me in the right direction.

thread434-627095
 
just remember that the function is executed in the clients browser, far away from the php server, so you can't call a php function from the form.

Logit could take you to another web page or open another window with a web page in it...
javascript...
function Logit(name, date) {
document.forms[0].action='+ name +'date=' + date;
document.forms[0].submit();
}

or see the javascript window.open() method
 
Yeah. i solved the problem by passing the varibles to a pop up and storing my variables in a session variable array.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top