InnerHTML IE 8 doesn't work properly? Resetting form - forms

Yeah this works in FF and Chrome, but for some reason wont work in IE 8. I'm using a radio button to clear a section of a form.. that section is a select box, but I don't want to leave the area empty - instead I want to reset it to what it was when the page loaded. At the moment IE8 is just leaving me with an empty small select box.
Html:
<select id="city_select" disabled="true" name="location_id" onchange="show_search_button();"><option selected>Select your city</option> </select>
Javascript:
document.getElementById('city_select').innerHTML = "<option selected>Select your city</option>";
I've also tried using location_id instead of city_select in the javascript but to no avail.. innerText and innerContent dont work either.. though the inner.HTML works in IE8 for an earlier function, but that isnt trying to innerHTML into a form. Does anybody know why this works in Chrome and FF but not IE8? and is there a solution to this? Any help appreciated thanks!

Try this:
document.getElementById('city_select').options.length = 0;
Then create a new option and push it onto the options array of the select. The options are a tricky bit that don't behave like other markup.
Edited to show how to create an option:
var sel = document.getElementById('city_select').options.length = 0;
var opt = document.createElement('option');
opt.value = "Select Your City";
sel.options.push(opt);
sel.selectedIndex = 0;

There are supposed to be 4 way of assigning new options to a select element. Some work in some scenarios and others work in others. Look here - How to Add options to <SELECT>, in IE Windows Mobile 5
For me, Robusto's solution didn't work due to three reasons:
1) sel variable in the first line is assigned document.getElementById('city_select').options.length = 0; instead of simply holding the select element (for later use in 4th and 5th line) and then deleting options in a next line, like this:
var sel = document.getElementById('city_select');
sel.options.length = 0;
2) the 4th line sel.options.push(opt) (or later suggested sel.options[0] = opt) throws an Object doesn't support this property or method error. Instead use this:
sel.appendChild(opt);
3) apart from assigning values to options you must also assign text to display. You do it like this:
opt.innerText = "Select Your City - displayed";
Therefore, to sum up the whole piece:
var sel = document.getElementById('city_select');
sel.options.length = 0;
var opt = document.createElement('option');
opt.value = "Select Your City";
opt.innerText = "Select Your City - displayed";
sel.appendChild(opt);
sel.selectedIndex = 0;

Related

Select a random node on every reload

I want to select a random node on every reload. My fusion file looks like this:
randomInt = ${Math.randomInt(0, q(node).children(Neos.Neos:Document).count()}
randomNode = ${q(node).children(Neos.Neos:Document).get(this.randomInt)}
Unfortunately the result is stored in the cache. That means that only after the cache get flushed a new node will be returned. How can I prevent this? I have already experimented with the cache rules a little bit, but I didn't come up with a solution yet.
The element that I want to use is on every page. That's why something like the unchached mode would be a really bad idea.
In my situation the output is only a array of strings. So I did following in my Fusion.
Generate "almost" a Array in Fusion
allMyStrings = Neos.Fusion:Loop {
items = ${q(node).children(Neos.Neos:Document).get()}
itemName = 'node'
itemRenderer = ${"'" + q(node).property('testString') + "'"}
#glue = ','
}
Pick a random array in JS
<p id='replaceMe'></p>
<script>
var quoteArray = [{allMyStrings -> f:format.raw()}]
var randomIndex = Math.floor(Math.random() * quoteArray.length);
var randomElement = quoteArray[randomIndex];
document.getElementById('replaceMe').outerHTML= '<p>' + randomElement + '</p>';
</script>
A bit hacky but it works and it don't harm the performance of the website

How to insert an option value into a select tag with CasperJS?

Well, the question is very self-explanatory.
Right now, I'm front of a form which has a select tag with a couple of options already. But I must insert a new one, with a different value that I will receive from a .json file.
The thing is: I haven't been able to find a suitable solution from the CasperJS documentation.
I've tried something like this:
this.fill('form.coworkerdiscountcode', {
'CoworkerDiscountCode.DiscountCode': ['Value1']
});
But no results. Any ideas?
Thanks in advance.
You can execute any javascript code by passing it to casper.evaluate like this:
casper.evaluate(function() {
var x = document.getElementById("coworkerdiscountcode");
var option = document.createElement("option");
option.text = "Kiwi";
x.add(option);
});

typoscript assign page:id to plugin attribute

so all I actually want to do is something like
plugin.tx_felogin_pi1.redirectPageLogin = page:id
where the page:id is the PID of the current page. replacing 'page:id' with a number works as expected BUT I do need the PID instead of a fixed number. any hints are welcome
redirectPageLogin has to be a single int value:
$redirect_url[] = $this->pi_getPageLink(intval($this->conf['redirectPageLogin']));
Alternative: use as $redirMethod: getpost or referer
I think that'll fit four you.
Try
plugin.tx_felogin_pi1.redirectPageLogin = TSFE:id
or
plugin.tx_felogin_pi1.redirectPageLogin = {TSFE:id}
or
plugin.tx_felogin_pi1.redirectPageLogin.cObject = TEXT
plugin.tx_felogin_pi1.redirectPageLogin.cObject.insertData = 1
plugin.tx_felogin_pi1.redirectPageLogin.cObject.value = {TSFE:id}

Typo3 - Custom email newsletters with direct_mail

Im building a newsletter and the start is like this:
DEAR ###USER_gender### ###USER_first_name### ###USER_last_name###
which outpouts
DEAR ###USER_gender### JOHN DOE
and I was hoping it would replace the gender mark with "Miss" and "Sir", depending on the value. How could I do this?
Extra fields have to be added to the field list (see docu). But I'm not sure whether this automatically works with non-string fields. Maybe using a hook is your solution or using another extension which adds a new field to tt_address.
Another solution is to nest marker:
###GENDER_###USER_gender######
and then warp you content in a new template object:
10 = TEMPLATE
10 {
template < yourAlreadyProcessedContent
marks {
GENDER_m = TEXT
GENDER_m.value = Sir
}
}
It's a bit unusual, but sometimes it's very useful.
(Personally I use it to replace version numbers in tt_content records.)
Edit:
Example for Dbugger:
Download the Introduction Package and install it. After that add to the Welcome page a new template record with the following steup:
temp.mainTemplate = TEMPLATE
temp.mainTemplate {
template = TEXT
template.value = (
Foo
###CONTENT###
###CONTENT###
Bar
)
subparts {
CONTENT < styles.content.get
}
}
page = PAGE
page {
typeNum = 0
10 = TEMPLATE
10 {
template < temp.mainTemplate
marks {
TEST = TEXT
TEST.value = ok
}
}
Now include CSS Styled Contnet and enable the following options:
clear constants, clear setup, rootlevel
The output should look like that:
Foo
Congratulations ...
Bar
If you add ###TEST### to the the tt_content record on the welcome page it will be replaced with ok.
This should work with direct mail, too.
Edit:
I'm sorry, this only works which normal extension which are use in the rendering process.
a little bit late, but here's the best solution for the salutation in direct_mail & tt_address .. works perfect for me. The personalized marker is just ###USER_salutation###,
https://blog.webentwickler.at/individuelle-marker-in-direct-mail/

Form Validation: Select

I'm trying to display an error message if the select button in my form is not changed. It works fine for the rest but not the select, please help! and I know that the image wont work like that, I cant post images as a new member.
Html is:
<div id='first_name_error' class='error'><image code here></div>
<div><input type='text' name='first_name' id='first_name' placeholder="YOUR FIRST NAME*"></div>
Number of Guests:*<div id='guests_error' class='error'><img src='img/booking/error.png'></div>
<div><select name='guests' id='guests' style="margin:0px;" SIZE="1"><OPTION SELECTED value="guests">Guests<OPTION>2<OPTION>3<OPTION>4</SELECT></div>
Code Is
var error = false;
var first_name = $('#first_name').val();
var second_name = $('#second_name').val();
var email = $('#email').val();
var number = $('#number').val();
var guests = $('#guests').val();
var message = $('#message').val();
if(first_name.length == 0){var error = true;$('#first_name_error').fadeIn(500);}else{$('#first_name_error').fadeOut(500);}
if(guests.value == Guests){var error = true;$('#guests_error').fadeIn(500);}else{$('#guests_error').fadeOut(500);}
Notice that your "guests" variable is already set to the value of the select element (using jQuery val()). There is no need to attempt to access the "value" property of the "guests" variable.
Second, the comparison you are making is to the identifier Guests, not to the string "Guests". You'll want to put quotes around that to make it a string literal.
You can see an example of this here: http://jsfiddle.net/tbuCJ/