/    Sign up×
Community /Pin to ProfileBookmark

Elementaing JavaScript

Hello,

Not sure if this belongs to the JS forum or HTML but here it goes.

I have a form that is being submitted by JS. I do this because the underlying program needs the value of a submit button that was clicked .

I used to do this like this(standard)

[CODE]<input type=”Submit” name=”submit_button” value=”Search”/>[/CODE]

and

[CODE]<input type=”Submit” name=”submit_button” value=”Add”/>[/CODE]

However, due to the new requirements I had to replace standard submit buttons by an image, like this

[CODE]<input type=”image” name=”sbm” src=”search.gif”
id=”search” value=”Search” style=”padding: 1px;” alt=”Search” >[/CODE]

and

[CODE]<input type=”image” name=”sbm” src=”add.gif”
id=”add” value=”Add” style=”padding: 1px;” alt=”Add” >[/CODE]

When I did this the browser (in this case IE 6) stopped passing value of the submit button.

I have to jump through hoops to pass an action to the form handler.I had to create a hidden field, JS function, as well as replace <input> element with <button> element, to submit a form.

Is there anyway to pass the value of the <input> element without using JS ?

Thanks

to post a comment
JavaScript

2 Comments(s)

Copy linkTweet thisAlerts:
@gil_davisFeb 14.2007 — The html <input type="image"> is designed to submit the x, y coordinates of where it was clicked.

You can style the submit button to use the image as the background of the button. See what you can do with this:
&lt;input type="submit" value="Submit" style="background: url('lilguy2.gif') fixed transparent no-repeat center; font-size: 0px; height: 30px; width: 80px"&gt;
Copy linkTweet thisAlerts:
@slaughtersFeb 14.2007 — If you are using image submit buttons, you need to provide different NAME attributes for them too. Do not call them both "sbm"

Call one "Add" and the other "Search" then simply check to see if Add.x or Search.x exist to know which one was used to submit the form.
×

Success!

Help @svager spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...