By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
445,876 Members | 1,191 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 445,876 IT Pros & Developers. It's quick & easy.

Passing a conditional form variable (Was: 'Trying to use images asform submit buttons')

P: n/a
Okay, I made sense of the earlier suggestions and realized I was on the
right track -- I appreciate the feedback which got me to this point.

The suggestions posted here indeed worked and eliminated the JavaScript
errors I was seeing. The fact that the target URL didn't execute was
because certain variables weren't being passed to it.

What I need to do is to pass a conditional variable to the target URL,
when the form is submitted, depending on which graphic button is pressed.

So, the form already sends several variables when the form is submitted
(at the onclick event). I've confirmed this by capturing the HTTP POST
variables and displaying them when the page executes.

Now, depending on which graphic button is selected, I would like to pass
another variable.

For example, when the Create button is pressed, I would like to pass
create=true (or something signifying that 'create' is set) to the target
URL.

How would I accomplish this? Any suggestions?

- Orest

On 2003-08-27 11:38 PM, Orest Kinasevych Saj remarked:
I'm trying to use images as form submit buttons along with JavaScript
but am having trouble getting these to work correctly. JavaScript
isn't one of my strengths.

Here's the current incarnation of my form and script (stripped to the
essentials):

----
<form name='frmcontact' method='post' enctype='multipart/form-data'>

Name:<input name='fname' type='text' size='10' value=''>

<input type='image' name='create' src='save.gif'
onclick='document.form.action="contacts.php"'>

</form>
----

The form executes correctly -- ie, all parameters are passed to the
target URL and processed correctly. (Not shown here in the interest
of simplicity are several input items of type=hidden. None of those
inputs has a name or value of 'action'.)

The problem is that IE and Mozilla complain of a JavaScript error.

The following error appears in IE6/Win:

----
'document.form' is null or not an object
----

The Mozilla JavaScript debugger reports the following error:

----
document.form has no properties
----
I've tried several variations and have consulted all requisite
resources for guidance, all to no avail.

Please help!


Jul 20 '05 #1
Share this Question
Share on Google+
1 Reply


P: n/a
> Now, depending on which graphic button is selected, I would like to pass
another variable.

For example, when the Create button is pressed, I would like to pass
create=true (or something signifying that 'create' is set) to the target
URL.


You could give your image tags names, like this:

<input type="image" src="create.gif" name="create" />
<input type="image" src="delete.gif" name="delete" />

on the other side in the form collection, you will see the x and y
coordinates of the image they pressed, such as

create.x = 34

delete.x = 46

so you can test for the length > 0 of create.x or delete.x
hope I have understood your problem correctly.
Sean Jorden
Norada Corp.
Jul 20 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.