jQuery change INPUT type – name or full field on forms

5 pts.
Tags:
INPUT element
INPUT tag
INPUT TYPE
JavaScript
JavaScript libraries
jquery
Web development
Web forms
Hi, I´m really busy on this, I need a Jquery to replace some form and input attributes because I´m using a third part script wich don´t give me a chance to change the ids and classes. I searched all internet and now I decided to post here... I need Jquery to change the fields (on page load).. basically this: (1) REPLACE ALL: <input type="checkbox" name="inputname" id="inputid" class="inputclass"/> TO THIS: <a href="http://....com" target="_blank"> <img src="http://...some.jpg" name="imgname" id="imgid" class="cf-box-b"/> </a> (2) CHANGE INPUT TYPE / NAME / CLASS / ID:
<input type="checkbox" name="inputname" id="inputid" class="inputclass"/>
TO THIS -SUBMIT-:
<input type="submit" name="inputname" id="inputid" class="inputclass"/>
OR THIS -CLASS:
<input type="checkbox" name="inputname" id="inputid" class="myownclass"/>
(3) ADD NAME / CLASS / ID TO FIELDSETS OR INPUTS:
<fieldset class="fieldsetclass">
TO THIS:
<fieldset class="fieldsetclass" name"myclassname">
OR INPUT FROM THIS:
<input type="submit">
TO THIS:
<input type="submit" name="myinputname">
--------------------------------------------------------------------------------- It´s basically a script to replace classes, ids, input types and it must replace on page load and must show the result when page load, not on click or on focus, etc... I hope it´s clear what I need... and hope you can help ! :-) I really need help on this because I´m going crazy with all Jquery code I wrote and nothing happens.
ASKED: December 21, 2008  3:21 PM
UPDATED: April 23, 2009  1:36 PM

Answer Wiki

Thanks. We'll let you know when a new response is added.

Remember to use $(document).ready(), otherwise the scripts will not work.

(1) You don’t want to lose context to your elements position, so I’d start by wrapping the existing input with the anchor and then swap out the input for the image:
<pre>$(“input.inputclass”).
wrap(‘<a href=”http://….com” target=”_blank”></a>’).
replaceWith(‘<img src=”http://…some.jpg” name=”imgname” id=”imgid” class=”cf-box-b”/>’).
remove();</pre>

(2) To change the type I would use replaceWith, but to change the class name use addClass and removeClass

(3) Use addClass for the fieldset, but to add an element name you should replace the element instead of modifying the “name” property, so use replaceWith

Discuss This Question:  

 
There was an error processing your information. Please try again later.
Thanks. We'll let you know when a new response is added.
Send me notifications when members answer or reply to this question.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Forgot Password

No problem! Submit your e-mail address below. We'll send you an e-mail containing your password.

Your password has been sent to:

To follow this tag...

There was an error processing your information. Please try again later.

REGISTER or login:

Forgot Password?
By submitting you agree to receive email from TechTarget and its partners. If you reside outside of the United States, you consent to having your personal data transferred to and processed in the United States. Privacy

Thanks! We'll email you when relevant content is added and updated.

Following