Forum Discussion
EverettPatterso
6 years agoQrew Captain
tdf# = div ID you want to target
Use F12 dev tools, select an element and target your fid 104
------------------------------
Everett Patterson
------------------------------
Use F12 dev tools, select an element and target your fid 104
------------------------------
Everett Patterson
------------------------------
BrandonClark
6 years agoQrew Cadet
Ok, 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
------------------------------
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
------------------------------
- AustinK6 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. - BrandonClark6 years agoQrew CadetYou nailed it. I let the original parameter back in on a copy/paste. The tab selection is working now. And I now understand how to check the parts along the way. You guys are awesome.
(Side note: For anyone else that is struggling with Javascript, I found this little tutorial to be a pretty efficient way to learn the basics - https://www.learn-js.org/ )
Now for the last piece, I need to take a stab at setting the Tab # field back to 0 after the focus. Will post what I figure out. Here's the code page as it stands:
(function () {
//Get the expected tab value
var QBUmytab = Number($("#tdf_2").text());
//Go to tab based on value
switch(QBUmytab) {
case 2:
$("#tab_t2_link a").click();
break;
case 3:
$("#tab_t3_link a").click();
break;
case 11:
$("#tab_t11_link a").click();
break;
case 20:
$("#tab_t20_link a").click();
break;
case 30:
$("#tab_t30_link a").click();
break;
};})();
------------------------------
Brandon Clark
------------------------------ - DonLarson6 years agoQrew EliteThanks for the JS link. It is becoming more and more important to dig into the browser. I will give it a long look over.
------------------------------
Don Larson
Paasporter
Westlake OH
------------------------------ - EverettPatterso6 years agoQrew CaptainYou will need to add the API_EditRecord call to each case and it will set that field back to 0 after it does the focus.
Replace dbid with your dbid
(function () { //Get the expected tab value var QBUmytab = Number($("#tdf_2").text()); //Go to tab based on value switch(QBUmytab) { case 3: $("#tab_t3_link a").click(); var dbidParents = "VALUE"; var rid = kRid; $.post(dbidParents, { act: "API_EditRecord", rid: rid, _fid_104: 0, }).then(function(xml) { }); break; case 4: $("#tab_t4_link a").click(); break; };})();
------------------------------
Everett Patterson
------------------------------ - BrandonClark6 years agoQrew CadetIt works brilliantly. Everett you are genius. Thank you.
------------------------------
Brandon Clark
------------------------------ - BrandonClark6 years agoQrew CadetStarting to see the first minor flaw in the plan. The fid_104 is required to be visible on the form for this work. I can live with that for now but any thoughts on a better way to pass the information without using it on the form?
------------------------------
Brandon Clark
------------------------------