Hi again, still working on my set up .... my friend would like me to add a couple of fields for people with special diet requirements.
I have a custom thread field called diet - its a radio button, options Yes or No.
I have a second custom thread field (I decided to make it a multiline textbox as there are so many possible variations) called diettext. What would be slick is that this textbox ONLY shows for input IF the selected diet option is Yes. I tried calling the globals threadfield value, but I think I have a fault in the syntax somewhere ....
Code:
<if ($GLOBALS['threadfields']['diet']['value']==Yes) then>
<td class="trow1" width="50%"><div>{$tfinput['diettext']}</div></td>
<else>WHUT
</if>
|
This above code just displays nothing, not even the WHUT shows up. Is it possible to do this or am I just doing it wrong?
Maybe something like this:
Code:
<if $GLOBALS['threadfields']['diet'] == "Yes" then>
|
Hi RateU - yes, I had tried that too - the thing is I was hoping it could be dynamic - like when I clicked the YES button then the field would popup.
The code above only works on a page refresh, which is not what I was going for. That's why i put the [value] in hoping that it would pick it up and update on screen without the refresh
I actually got a kind of link going using a scriptaculous thing, but the user had to click on the WORD yes rather than the radio button, so it opened the div slickly but was not choosing the YES field. I tried the scriptaculous in a dropbox, but that was a fail as the text in the drop was the javascript.
I will continue to prod at it.
You need Javascript to do that. PHP only works on the server, so if you want something to change dynamically on the client side, you need a client side script (ie Javascript).
Yes, I tried using a scriptaculous snippet - and I did kind of get it to work, but instead of launching when the user clicked on the radio button, the user needed to click on the WORD yes (the option value) which meant that the radio button was not chosen. What I am struggling with is to get my snippet to run when they click on the button.
I'm not sure about the JS library you're using, but make sure that you're sticking the event (onchange or similar) on the option button, not the text or label.
This is actually the problem - I don't know how to put the event on the button - I don't really get which of the formats to change.
This is my code to attach to the button:
Code:
<a href="javascript:;" onclick="Effect.toggle('field', 'slide', { duration: 0.5 });">BUTTON NAME</a>
|
And this is what I will wrap the "appearing" multiline text box in:
Code:
<div id="field" style="display: none;">
<div>
Custom thread field
</div>
</div>
|
It does work as a piece of code, but not from the radio button - just from the label.
I had a look round on the internet - and found various snippets to try and get the variables - here is one -
Code:
<script type="text/javascript">
//a variable that will hold the index number of the selected radio button
for (i=0;i<document.test.myradio.length;i++){
if (document.test.myradio[i].checked==true)
theone=i
}
</script>
|
But I can't find WHERE the variables are stored - I did a view source and got this:
Code:
<td class="trow1" width="50%"><div><label style="display: block; font-style: italic;"><input name="xthreads_diet" class="radio" value="" tabindex="__xt_9" type="radio">(Not set)</label><label style="display: block;"><input name="xthreads_diet" class="radio" value="Yes" checked="checked" type="radio">Yes</label><label style="display: block;"><input name="xthreads_diet" class="radio" value="No" type="radio">No</label></div></td>
|
(02-09-2011 10:16 AM)ZiNgA BuRgA Wrote: [ -> ]Thanks for that....
Sure, it took a little while to track down the root cause of the error; Figuring out a solution was a good learning experience.
(02-09-2011 10:16 AM)ZiNgA BuRgA Wrote: [ -> ]...Perhaps this is a reason for not using an external forum cache...
Normal usage will *not* produce this error
@leefish ...well, you're putting the code in an <a> tag, not the actual input field.
Something like (can't remember ID of the form, change it if none is set)
Javascript Code
document.getElementById('myform').xthreads_diet.onchange = function() {
};
|
Hmmm, well, I am horribly confused.
I ran a little test function on my new thread - I put this code in the template:
Javascript Code
<script language="javascript" type="text/javascript">
var el = document.getElementById('xthreads_diet');
if (el)
el.onchange = function() { alert('changed'); }
else
alert("element not found");
</script>
|
To check that I had the data in right - but it fired the element not found. When I took the single quotes off 'xthreads_diet' then nothing happened.
I think this is beyond my small skill set at the moment, so I will have to give up for now. Thank you for your time Zinga, and I'm sorry I can't "get it", I am still new to javascript, so.