Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Can I src an image within a form using javascript
Old 07-20-2009, 07:53 PM Can I src an image within a form using javascript
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
I want to src my submit button in a form using javascript. Is this possible?

It would look something like this but with the src coming from javascript.

<input type="image" name="SubmitFormBut" src="img/Submit.gif" alt="Submit Form" height="22" width="91">
ericson3000 is offline
Reply With Quote
View Public Profile
 
 
Register now for full access!
Old 07-20-2009, 08:22 PM Re: Can I src an image within a form using javascript
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
You wouldn't have to change the code you have, though you probably want to add an id to the input. You could write your JavaScript to hook into the id document.getElementById('your-id') and then programmatically change the src of the input in any way you like.
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-20-2009, 08:29 PM Re: Can I src an image within a form using javascript
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
Thanks. Pardon my ignorance, I'm not a javascript coder.

So I would and and Id="whatever" to my input. Then in my head I would write a piece of js would get the img/Submit.gif from its location and tell it to use it in my input? Is this done by a variable or function?
ericson3000 is offline
Reply With Quote
View Public Profile
 
Old 07-20-2009, 08:50 PM Re: Can I src an image within a form using javascript
vangogh's Avatar
Post Impressionist

Posts: 10,688
Name: Steven Bradley
Location: Boulder, Colorado
Trades: 0
Yep. You add the id and then in the javascript you can reference it through the getElementById() tag. Assuming you use an id="SubmitFormBut" then in your javascript you could have

var button = document.getElementById('SubmitFormBut');
var buttonSrc = button.src;

You could also combine the above into one statement.

What you want to do from there depends on what you're trying to do. Why do you want to change the image? What will cause the image to change? Is it a rollover or is it based on a specific page or based on the user?
__________________
l Search Engine Friendly Web Design |
Please login or register to view this content. Registration is FREE

l Tips On Marketing, SEO, Design, and Development |
Please login or register to view this content. Registration is FREE

l
Please login or register to view this content. Registration is FREE
|
Please login or register to view this content. Registration is FREE
vangogh is offline
Reply With Quote
View Public Profile Visit vangogh's homepage!
 
Old 07-21-2009, 02:29 PM Re: Can I src an image within a form using javascript
ericson3000's Avatar
Experienced Talker

Posts: 40
Name: Bob Davis
Location: Los Angeles, CA
Trades: 0
Hey fantastic. Thanks for the help.

Yeah, rollover based on the user. We have several portals where clients log in and we intend to customize certain elements on the page, one being the submit button on our form.

Okay, so my id="SubmitFormBut".

And I put the javascript in the head like so:

<script type="text/javascript">
function()
var button = document.getElementById('SubmitFormBut');
var buttonSrc = button.src;
</script>

The body tag would be:

<input type="image" name="SubmitFormBut" id="SubmitFormBut" src="img/button.gif" alt="Submit Form" height="22" width="91">


And what happens if they have their browser's javascript turned off?
ericson3000 is offline
Reply With Quote
View Public Profile
 
Reply     « Reply to Can I src an image within a form using javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.14944 seconds with 12 queries