Reputation: 69
A while ago I asked this question where I was taught to make the label of a form input change according to what was selected in a dropdown div. All using javascript.
That was great but I went away and have only come back to it now and realized I actually need to collect that information as part of the form.
I'm using cakephp and that form goes to the register action in my users_controller, in that action I need to be able to tell which currency has been selected as well as how much they've typed in. I know I can get at how much they've typed in with $this->['User']['target'] but is there anyway to find out which currency they've selected or does that need to be an input too?
sorry for this probably being a real newb question but I am one :)
Thanks Sarah
Upvotes: 0
Views: 108
Reputation: 5481
what's in that dropdown div? and why don't you use select element?
you can just have this echo $this->Html->input('currency',array('options'=>array('0'=>'dollar','1'=>'pound')));
Upvotes: 0
Reputation: 7489
You can get at that via
$("#currencylabel").text();
or
$("#currencylabel").val();
or another variation, depending on what kind of element you are using for the label.
Edit: this will get you the value in javascript, if you want it in PHP you will need to either put it in an input or post it back with javascript once you get it.
Edit 2: To recommended method to get it would be to just make it an input, or to add a hidden input to the form. The hidden input would require that you change its value via javascript whenever a different currency is selected. This way, when you process the form in PHP, you will have the information there just as you have the value the user entered.
Since the user is selecting a currency, I assume you already have some sort of input in place to allow them to do that (not sure what this dropdown div entails). If that's part of the form, you already have what you need. If not, either include it in the form (if possible), or (if not) add a hidden input and update its value whenever you change the label.
Upvotes: 1