Forum Discussion
AustinK
Qrew Commander
Given the code above adding in the debugging is the easier part. You should get used to adding it in yourself because it helps you learn as you go.
What I would do is start simple, a console.log(QBUmytab); after the variable is set in the code. If you see that it is returning something then go from there. Make sure it is returning what is expected which is some type of number, and if it is returning anything but the numbers listed(3 or 4) then it doesn't have anything in the code to call. If it is returning a 3 or 4 then chances are the code for those may not be exactly right.
What I would do is start simple, a console.log(QBUmytab); after the variable is set in the code. If you see that it is returning something then go from there. Make sure it is returning what is expected which is some type of number, and if it is returning anything but the numbers listed(3 or 4) then it doesn't have anything in the code to call. If it is returning a 3 or 4 then chances are the code for those may not be exactly right.
BrandonClark
5 years agoQrew Cadet
Thanks Austin. It appears the QBUmytab variable is not getting defined. Did #tdf_1 need to be edited for my implementation or does that convert to fid_104? I've tried simply changing to tdf_104 with no luck.
(function () {
//Get the expected tab value
var QBUmytab = Number($("#tdf_1").text());
console.log(QBUmytab);
//Go to tab based on value
switch(QBUmytab) {
case 3:
$("#tab_t3_link a").click();
break;
case 4:
$("#tab_t4_link a").click();
break;
};})();
And I agree on getting used to adding the troubleshooting code. I probably have 30 hours into just trying to accomplish this one task. But if I have this snip with the code to debug each step along the way then I can start using this as my reference example to build out from and start getting some context to better understand the javascript documentation.
Thx again,
Brandon
------------------------------
Brandon Clark
------------------------------
(function () {
//Get the expected tab value
var QBUmytab = Number($("#tdf_1").text());
console.log(QBUmytab);
//Go to tab based on value
switch(QBUmytab) {
case 3:
$("#tab_t3_link a").click();
break;
case 4:
$("#tab_t4_link a").click();
break;
};})();
And I agree on getting used to adding the troubleshooting code. I probably have 30 hours into just trying to accomplish this one task. But if I have this snip with the code to debug each step along the way then I can start using this as my reference example to build out from and start getting some context to better understand the javascript documentation.
Thx again,
Brandon
------------------------------
Brandon Clark
------------------------------
- EverettPatterso5 years agoQrew Captaintdf# = div ID you want to target
Use F12 dev tools, select an element and target your fid 104
------------------------------
Everett Patterson
------------------------------- BrandonClark5 years agoQrew CadetOk, that was really good info. So here's my first shot at dividing it up. Both of the alerts with the values are displaying NaN.
It is not making into the Case 11 as expected.
(function () {
//Get the expected tab value
alert("lets go fishing");
alert( Number($("#tdf_1").text());
var QBUmytab = Number($("#tdf_1").text());alert(QBUmytab);
//Go to tab based on value
switch(QBUmytab) {
case 11: alert("No way, it's too nice out.");
$("#tab_t11_link a").click();
alert("But there's free bait!");
break;
case 13:
$("#tab_t13_link a").click();
break;
};})();
------------------------------
Brandon Clark
------------------------------- AustinK5 years agoQrew CommanderSo is tdf_1 your field that you found through the method Everett described? The error your are getting is telling you the field you are trying to convert into a number is not a number(NaN).
I wouldn't normally use so many alerts but if you want to know what the field is just go to your form and type this into console.
alert($("#tdf_1").text())
And tell us what that says. I still feel like you just need to adjust the #tdf_1 part to be the correct number for your field you are wanting to check.