I’d made a Selection form for mysite and wanted to add my form results to a database.
In the case of a selection between multiple items I wanted to add to my existing buttons the ability to select an item in the dropdown from a button.
To do this I tried adding “$w(‘#dropdownN’).selectedIndex=N;” to my buttons, this changes what’s shown on the dropdown, but when submit(Order) is pressed dropdowns selected via this method are not written to the database.
Note: If the item is selected via the dropdown it is written to the database.
If you could tell me what code I’m missing that would be great.
Page in question: https://www.stripe21.com/copy-of-mobile-bundles (Please excuse the poor lining up of things, this will be fixed in the finished page)
Yep, had the exact same problem! I could save out the selection when clicked from the drop-down, but not when set via .selectedIndex.
As it happens, my code to selectedIndex was within the $w.onReady function, but after moving the code outside of the $w.onReady function, IT WORKED !!!
Thanks for the suggestion, my code was already outside of the $w.onReady function.
I’ve rewritten It re-arranging the functions with polymorphism so the code is easier to update and re-use, unfortunately the problem persists.
Hi Toby,
Yes I realised later that my suggestion was a red herring and that the problem I was seeing was actually intermittent. In my case I am writing the button press results to a database which I then query when the relevant page loads with the drop-down list-box. I was sure that the problem was related to timing, but not convinced now.
I have now tried preceding my function calls with the ‘export’ keyword, as this is how the event trigger stubs are written by default. Seems to be working so far, both in preview and live mode, but will do more testing - feels like groping in the dark now.
Thanks again for the suggestion unfortunately my functions are called from other functions so can’t be made into export functions, otherwise I get a “Parsing Error: Unexpected token”.
Making the parent function into an export function doesn’t seem to make any difference.
I’ve added the part of my code below.
cheers
Toby
export function Phone(name, price, selected, button, box, dropDownIndex) { this.nam e = name; this .price = price; this .selected = selected; this .button = button; this .box = box; this .dropDownIndex = dropDownIndex;
}
Phone.prototype.buttonClicked = function () {// if ( this .selected === false ) {
DeselectPhone() this .selected = true ;
$total = $total + this .price;
$w( this .button).style.backgroundColor = $selButtonColor;
$w( this .button).style.color = $selTextColor;
$w( this .box).style.backgroundColor = $selBoxColor;
$w(‘#dropdown2’).selectedIndex = this .dropDownIndex;
} else {
DeselectPhone();
}
updatePrice();
};
I’m also seeing this. The checkbox group passes the required validation but no tags are saved to the database. So far I’ve only tested data binding through the editor.
Checking the boxes with the mouse means the tags will be saved on form submit. Values changed with selectedIndex (and seeing that change reflected in the UI) get thrown away.