Jump to content

is this possible?


mga_ka_php

Recommended Posts

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.

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

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>

 

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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)

Link to comment
Share on other sites

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 ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.