Hello
I have setup a form that has the required field code applied to the Load JS ( see below ).
I have also created another Script that shows the information for users in the field which then disappears when clicked ( similar to the label placeholder script) which works fine on its own. (see this code below also)
Problem is If I try to run them both at once neither one works! I have tried loading them as separate load JS actions and have also merged them together but still no luck. Can anybody out there look at the code and tell me where I have gone wrong....any help greatly appreciated!
Show required field code
[code]window.addEvent('domready', function() {
var required, cl, inputs, input, label, type, name, skip, marker;
marker = new Element('span', {
html: ' *',
styles: {
color: 'red',
fontWeight: 'normal'
}
});
inputs = $$('div input, div select, div textarea');
required = [];
inputs.each(function(el) {
cl = el.getProperty('class');
if(cl !== null && (cl.contains("validate['required'") || cl.contains("validate['group["))) {
required.push(el);
}
});
required.each(function(el) {
el.addClass('cf_required');
skip = false;
type = el.getProperty('type');
if(type == 'radio' || type == 'checkbox') {
if(name != el.getProperty('name')) {
label = el.getParent().getParent().getFirst('label');
name = el.getProperty('name');
} else {
skip = true;
}
} else {
label = el.getParent().getFirst('label');
}
if(label && !skip) {
label.grab(marker.clone(), 'bottom');
label.addClass('cf_required');
}
});
});
$('input, textarea').each(function () {
var Input = $(this);
var default_value = Input.val();
Input.focus(function() {
if(Input.val() == default_value) Input.val("");
}).blur(function(){
if(Input.val().length == 0) Input.val(default_value);
});
});[/code]
Show info for users in form fields code
* Both of the above work fine on their own but not when loaded together
This is Combined code that also isn't working
[code]window.addEvent('domready', function() {
// initialise the form
var inputs2 = $$('#chronoform_Quote input[type=text], textarea'); inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( !my_input.value ) {
my_input.value = tip.getProperty('text');
my_input.setStyle('color', '#f00');
tip.setStyle('display', 'none');
}
showtip(my_input);
});
// add events to fire when the submit button is clicked
$('submit').addEvent('click', function() {
inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( my_input.value == tip.getProperty('text') ) {
my_input.value = '';
my_input.setStyle('color', '#000');
}
}); });
// add events to fire when the submit button loses focus
$('submit').addEvent('mouseout', function() {
inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( my_input.value == '' ) {
my_input.value = tip.getProperty('text');
my_input.setStyle('color', '#FFF');
my_input.set('tween', {duration: 'long'});
my_input.tween('color', '#888');
}
}); });
});
// initialisation function adds events to each input
function showtip(my_input) {
var tip = my_input.getParent().getElement('div');
if ( !my_input.value ) {
my_input.value = tip.getProperty('text');
}
tip.setStyle('display', 'none');
my_input.addEvent('focus', function() {
var tip = this.getParent().getElement('div');
if ( this.value == tip.getProperty('text') ) {
this.value = '';
this.setStyle('color', '#000');
}
});
my_input.addEvent('blur', function() {
var tip = this.getParent().getElement('div');
if ( this.value == '' ) {
this.value = tip.getProperty('text');
this.setStyle('color', '#888');
}
});
my_input.addEvent('submit', function(){
var tip = this.getParent().getElement('div');
if ( this.value == tip.getProperty('text') ) {
this.value = '';
this.setStyle('color', '#000');
}
});
var required, cl, inputs, input, label, type, name, skip, marker;
marker = new Element('span', {
html: ' *',
styles: {
color: 'red',
fontWeight: 'normal'
}
});
inputs = $$('div input, div select, div textarea');
required = [];
inputs.each(function(el) {
cl = el.getProperty('class');
if(cl !== null && (cl.contains("validate['required'") || cl.contains("validate['group["))) {
required.push(el);
}
});
required.each(function(el) {
el.addClass('cf_required');
skip = false;
type = el.getProperty('type');
if(type == 'radio' || type == 'checkbox') {
if(name != el.getProperty('name')) {
label = el.getParent().getParent().getFirst('label');
name = el.getProperty('name');
} else {
skip = true;
}
} else {
label = el.getParent().getFirst('label');
}
if(label && !skip) {
label.grab(marker.clone(), 'bottom');
label.addClass('cf_required');
}
});
$('input, textarea').each(function () {
var Input = $(this);
var default_value = Input.val();
Input.focus(function() {
if(Input.val() == default_value) Input.val("");
}).blur(function(){
if(Input.val().length == 0) Input.val(default_value);
});
});
};[/code]
I have setup a form that has the required field code applied to the Load JS ( see below ).
I have also created another Script that shows the information for users in the field which then disappears when clicked ( similar to the label placeholder script) which works fine on its own. (see this code below also)
Problem is If I try to run them both at once neither one works! I have tried loading them as separate load JS actions and have also merged them together but still no luck. Can anybody out there look at the code and tell me where I have gone wrong....any help greatly appreciated!
Show required field code
[code]window.addEvent('domready', function() {
var required, cl, inputs, input, label, type, name, skip, marker;
marker = new Element('span', {
html: ' *',
styles: {
color: 'red',
fontWeight: 'normal'
}
});
inputs = $$('div input, div select, div textarea');
required = [];
inputs.each(function(el) {
cl = el.getProperty('class');
if(cl !== null && (cl.contains("validate['required'") || cl.contains("validate['group["))) {
required.push(el);
}
});
required.each(function(el) {
el.addClass('cf_required');
skip = false;
type = el.getProperty('type');
if(type == 'radio' || type == 'checkbox') {
if(name != el.getProperty('name')) {
label = el.getParent().getParent().getFirst('label');
name = el.getProperty('name');
} else {
skip = true;
}
} else {
label = el.getParent().getFirst('label');
}
if(label && !skip) {
label.grab(marker.clone(), 'bottom');
label.addClass('cf_required');
}
});
});
$('input, textarea').each(function () {
var Input = $(this);
var default_value = Input.val();
Input.focus(function() {
if(Input.val() == default_value) Input.val("");
}).blur(function(){
if(Input.val().length == 0) Input.val(default_value);
});
});[/code]
Show info for users in form fields code
window.addEvent('domready', function() {
// initialise the form
var inputs2 = $$('#chronoform_Quote input[type=text], textarea'); inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( !my_input.value ) {
my_input.value = tip.getProperty('text');
my_input.setStyle('color', ‘#000');
tip.setStyle('display', 'none');
}
showtip(my_input);
});
// add events to fire when the submit button is clicked
$('submit').addEvent('click', function() {
inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( my_input.value == tip.getProperty('text') ) {
my_input.value = '';
my_input.setStyle('color', '#000');
}
}); });
// add events to fire when the submit button loses focus
$('submit').addEvent('mouseout', function() {
inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( my_input.value == '' ) {
my_input.value = tip.getProperty('text');
my_input.setStyle('color', '#FFF');
my_input.set('tween', {duration: 'long'});
my_input.tween('color', '#888');
}
}); });
});
// initialisation function adds events to each input
function showtip(my_input) {
var tip = my_input.getParent().getElement('div');
if ( !my_input.value ) {
my_input.value = tip.getProperty('text');
}
tip.setStyle('display', 'none');
my_input.addEvent('focus', function() {
var tip = this.getParent().getElement('div');
if ( this.value == tip.getProperty('text') ) {
this.value = '';
this.setStyle('color', '#000');
}
});
my_input.addEvent('blur', function() {
var tip = this.getParent().getElement('div');
if ( this.value == '' ) {
this.value = tip.getProperty('text');
this.setStyle('color', '#888');
}
});
my_input.addEvent('submit', function(){
var tip = this.getParent().getElement('div');
if ( this.value == tip.getProperty('text') ) {
this.value = '';
this.setStyle('color', '#000');
}
});
};
* Both of the above work fine on their own but not when loaded together
This is Combined code that also isn't working
[code]window.addEvent('domready', function() {
// initialise the form
var inputs2 = $$('#chronoform_Quote input[type=text], textarea'); inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( !my_input.value ) {
my_input.value = tip.getProperty('text');
my_input.setStyle('color', '#f00');
tip.setStyle('display', 'none');
}
showtip(my_input);
});
// add events to fire when the submit button is clicked
$('submit').addEvent('click', function() {
inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( my_input.value == tip.getProperty('text') ) {
my_input.value = '';
my_input.setStyle('color', '#000');
}
}); });
// add events to fire when the submit button loses focus
$('submit').addEvent('mouseout', function() {
inputs2.each(function(my_input) {
var tip = my_input.getParent().getElement('div');
if ( my_input.value == '' ) {
my_input.value = tip.getProperty('text');
my_input.setStyle('color', '#FFF');
my_input.set('tween', {duration: 'long'});
my_input.tween('color', '#888');
}
}); });
});
// initialisation function adds events to each input
function showtip(my_input) {
var tip = my_input.getParent().getElement('div');
if ( !my_input.value ) {
my_input.value = tip.getProperty('text');
}
tip.setStyle('display', 'none');
my_input.addEvent('focus', function() {
var tip = this.getParent().getElement('div');
if ( this.value == tip.getProperty('text') ) {
this.value = '';
this.setStyle('color', '#000');
}
});
my_input.addEvent('blur', function() {
var tip = this.getParent().getElement('div');
if ( this.value == '' ) {
this.value = tip.getProperty('text');
this.setStyle('color', '#888');
}
});
my_input.addEvent('submit', function(){
var tip = this.getParent().getElement('div');
if ( this.value == tip.getProperty('text') ) {
this.value = '';
this.setStyle('color', '#000');
}
});
var required, cl, inputs, input, label, type, name, skip, marker;
marker = new Element('span', {
html: ' *',
styles: {
color: 'red',
fontWeight: 'normal'
}
});
inputs = $$('div input, div select, div textarea');
required = [];
inputs.each(function(el) {
cl = el.getProperty('class');
if(cl !== null && (cl.contains("validate['required'") || cl.contains("validate['group["))) {
required.push(el);
}
});
required.each(function(el) {
el.addClass('cf_required');
skip = false;
type = el.getProperty('type');
if(type == 'radio' || type == 'checkbox') {
if(name != el.getProperty('name')) {
label = el.getParent().getParent().getFirst('label');
name = el.getProperty('name');
} else {
skip = true;
}
} else {
label = el.getParent().getFirst('label');
}
if(label && !skip) {
label.grab(marker.clone(), 'bottom');
label.addClass('cf_required');
}
});
$('input, textarea').each(function () {
var Input = $(this);
var default_value = Input.val();
Input.focus(function() {
if(Input.val() == default_value) Input.val("");
}).blur(function(){
if(Input.val().length == 0) Input.val(default_value);
});
});
};[/code]