mga_ka_php Posted March 14, 2007 Share Posted March 14, 2007 i am currently in the process of developing a website using php and mysql. but have a problem with my script. <form method="post" name="form1"> <input type="textbox" name="username"> <input type="textbox" name="password"> <a onclick="javascript:document.form1.submit('user.php?do=add');"><img border="0" style="cursor:hand" src="add.gif"></a> <a onclick="javascript:document.form1.submit('user.php?do=edit');"><img border="0" style="cursor:hand" src="edit.gif"></a> </form> actually, this script works if i am doing it in windows. i installed easyphp in my computer. but in the office, i am using fedora 6. and this code doesn't work at all. when i click the button. it only bounces me back to the same page. it doesn't direct me to the specified page. and i think it is in the browser i am using. at my house i use internet explorer. but in the office i use firefox2. what i need to do to be able to make this script work in both browser? thanks a lot. Quote Link to comment Share on other sites More sharing options...
obsidian Posted March 14, 2007 Share Posted March 14, 2007 First off, you need to be adjusting your action to reflect the page you're wanting to submit to. Try something like this: <script type="text/javascript"> var myForm = document.forms[0]; function submitAdd() { myForm.action = "users.php?do=add"; myForm.submit(); } function submitEdit() { myForm.action = "users.php?do=edit"; myForm.submit(); } </script> <a href="#" onclick="return submitAdd();">new</a> <a href="#" onclick="return submitEdit();">edit</a> Also, I'm moving this to the javascript forum since it has nothing to do with PHP Quote Link to comment Share on other sites More sharing options...
per1os Posted March 14, 2007 Share Posted March 14, 2007 Look on w3c at the javascript document and form and see if it is supported by firefox. You also need an action set in the form method, probably need to do a JS function. My bad i realize that this automatically takes </a> and converts it to [/url], use the code tags next time, it lets us see exactly what it should look like. <form method="post" name="form1"> <input type="textbox" name="username"> <input type="textbox" name="password"> <a href="#" onclick="javascript:document.form1.submit('user.php?do=add');"><img border="0" style="cursor:hand" src="add.gif"></a> <a href="#" onclick="javascript:document.form1.submit('user.php?do=edit');"><img border="0" style="cursor:hand" src="edit.gif"></a> </form> Quote Link to comment Share on other sites More sharing options...
ToonMariner Posted March 14, 2007 Share Posted March 14, 2007 why use javascript to submit forms???? html has these wonderful things called buttons and if you use a submit button every browser that comes across it will understand. You can give each a different name and use that to decide if you are adding or editing (better to use a different method of detection though - like if a unique identifier is present or not) Quote Link to comment Share on other sites More sharing options...
mga_ka_php Posted March 15, 2007 Author Share Posted March 15, 2007 how do you do that in button? <form method="post" name="form1"> <input type="textbox" name="username"> <input type="textbox" name="password"> <button onclick="javascript:document.form1.submit('user.php?do=add');"> <button onclick="javascript:document.form1.submit('user.php?do=edit');"> </form> like this? why use javascript to submit forms???? html has these wonderful things called buttons and if you use a submit button every browser that comes across it will understand. You can give each a different name and use that to decide if you are adding or editing (better to use a different method of detection though - like if a unique identifier is present or not) Quote Link to comment Share on other sites More sharing options...
mga_ka_php Posted March 15, 2007 Author Share Posted March 15, 2007 i used this script but it doesn't work? First off, you need to be adjusting your action to reflect the page you're wanting to submit to. Try something like this: <script type="text/javascript"> var myForm = document.forms[0]; function submitAdd() { myForm.action = "users.php?do=add"; myForm.submit(); } function submitEdit() { myForm.action = "users.php?do=edit"; myForm.submit(); } </script> <a href="#" onclick="return submitAdd();">new</a> <a href="#" onclick="return submitEdit();">edit</a> Also, I'm moving this to the javascript forum since it has nothing to do with PHP Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.