Jump to content

Xiang

Caspio Guru
  • Content Count

    75
  • Joined

  • Last visited

  • Days Won

    9

Everything posted by Xiang

  1. Hi ccarls3, How are you doing? I've wrote a simple script: if an image field is empty, the error message is displayed. When a user clicks the second time, the record is added. You can add as many fields as you want. <SCRIPT LANGUAGE="JavaScript"> var first_time = true; function check_images() { var image1 = document.getElementById("InsertRecordfile1").value; var image2 = document.getElementById("InsertRecordfile2").value; var image3 = document.getElementById("InsertRecordfile3").value; var emptyFields = false; if (image1.length < 1) emptyFields = true; if (image2.length < 1) emptyFields = true; if (image3.length < 1) emptyFields = true; if ( emptyFields) { if (first_time) { first_time = false; alert("Image field is empty. If you want to continue, please click Submit again"); return false; } } } document.getElementById("caspioform").onsubmit=check_images; </SCRIPT> If you want a pop-up window, I'll try writing a new code Have a nice day!
  2. Hi ViralSports, The Testc field should be editable and the "rich text editing toolbar" checkbox on the Advanced tab should be unchecked. I have copied-and-pasted your code, it works on my page. Have a nice day!
  3. I can I have wrote more universal script, you can add days, months, and years. If you want add only month, set "0" for days and years. And do not forget to enter the name of your field instead of "NAME_OF_YOUR_FIELD" <SCRIPT LANGUAGE="JavaScript"> function setDate() { var plusDays = 0; var plusMonths = 6; var plusYears = 0; var fieldname = "NAME_OF_YOUR_FIELD"; var myDate = new Date(); myDate.setDate(myDate.getDate()+plusDays); myDate.setMonth(myDate.getMonth()+plusMonths); myDate.setFullYear(myDate.getFullYear()+plusYears); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myMonth + "/" + myDay + "/" + myYear; fieldname = "InsertRecord"+fieldname; document.getElementById(fieldname).value=result; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> Have a nice day!
  4. Hi MikeP, How are you? I've written the code (you can add an HTML Block, place it the last element, click the Source button and enter the code): Do not forget to change "id" in two places ([@field:id]) - enter the name of your field with unique value (usually it is a field with the Autonumber DataType) and enter your values in blocks "first possible value", "second possible value". You can use as many blocks as you want. <div id="[@field:id]"></div> <SCRIPT LANGUAGE="JavaScript"> var line_id='[@field:id]'; var number_records_per_page = 25; //Records per page var line=document.getElementById(line_id).parentNode.parentNode; var elems = line.getElementsByTagName("td"); var myColor = ""; var mybgColor = ""; var colorAll = false; var comparisonText = ""; if(elems[0].innerHTML==" ") { var isGroup = elems[0].parentNode.previousSibling.getElementsByTagName("td")[0]; if(isGroup.innerHTML==" ") { for(i = 1; i < number_records_per_page; i++) { isGroup = isGroup.parentNode.previousSibling.getElementsByTagName("td")[0]; if(isGroup.innerHTML!=" ") break; } } comparisonText = isGroup.innerHTML; } else { comparisonText = elems[0].innerHTML; } //first possible value if (comparisonText =="test" || comparisonText =="test (Cont.)") //enter your value instead of test { myColor="blue"; //enter your text color instead of blue mybgColor="yellow"; //enter your background color instead of yellow var colorAll = true; } //second possible value if (comparisonText =="test" || comparisonText =="test (Cont.)") //enter your value instead of test { myColor="red"; //enter your color instead of red mybgColor="green"; //enter your background color instead of green var colorAll = true; } if(colorAll) { for (var i=0, m=elems.length; i<m; i++) { elems[i].style.color=myColor; elems[i].style.backgroundColor=mybgColor; } } </SCRIPT> I'll be grateful, if you tell me if the code works. Have a nice day!
  5. Hi everyone, I hope you are doing well. I like solution for Responsive Tabular DataPages, but if I deploy two DataPages on a webpage, names of the second DataPage replace names of the first. I've found the solution and want to share it: Edit the second DataPage, go to the "Configure Results Page Fields" step, go to the header of the second DataPage, find the part: #tabular table[class^=cbResultSetTable] td:nth-of-type(1):before { content: "Insert Label Here"; font-weight: bold; } #tabular table[class^=cbResultSetTable] td:nth-of-type(2):before { content: "Insert Label Here"; font-weight: bold; } #tabular table[class^=cbResultSetTable] td:nth-of-type(3):before { content: "Insert Label Here"; font-weight: bold; } #tabular table[class^=cbResultSetTable] td:nth-of-type(4):before { content: "Insert Label Here"; font-weight: bold; } } </style> <div id="tabular"> <!-- Responsive Code End --> And replace all "#tabular" and "tabular" to "#myID" and "myID", then the whole code will be like follows: #myID table[class^="cbResultSetTable"] td:nth-of-type(1):before { content: "Insert Label Here"; font-weight: bold; } #myID table[class^="cbResultSetTable"] td:nth-of-type(2):before { content: "Insert Label Here"; font-weight: bold; } #myID table[class^="cbResultSetTable"] td:nth-of-type(3):before { content: "Insert Label Here"; font-weight: bold; } #myID table[class^="cbResultSetTable"] td:nth-of-type(4):before { content: "Insert Label Here"; font-weight: bold; } } </style> <div id="myID"> <!-- Responsive Code End --> If you have any problems - feel free to ask, I'll be glad to help. Have a nice day!
  6. Hi aam82, How are you doing? What code do you use? I clicked the link, but page was not found. If you post the code, maybe I can help. Have a nice weekend!
  7. Hi Peter, It's for Footer, and please don't forget to click the "Source" button.
  8. Hi peterhanse, Welcome to the Forum! How are you? I think, you can use the following code: <script> var column_number = 1; var myTable = document.getElementsByName("cbTable")[0]; var myRows = myTable.getElementsByTagName("tr"); var lastRow = myRows.length - 1; var myCells = myRows[lastRow].getElementsByTagName("td"); var myTotal = parseFloat(myCells[column_number].innerHTML); var paard = "voeg uw paard toe!"; var voegtoe = "upgrade uw acount!"; if(myTotal>0) { document.write("<p>Link: " + paard.link("http://google.nl") + "</p>") } else { document.write("<p>Link: " + voegtoe.link("http://caspio") + "</p>") } </script> Where column_number is the number of the Aggregation. If you use only one Aggregation, it'll be "1". I'll be grateful, if you tell me if the code works. Have a nice day!
  9. Hi Elena, I've worked with your code. In my form the following code works: <script> var v_Knowledge_New = "[@field:Knowledge_New]" ; var o_Knowledge_New= document.getElementById("EditRecordKnowledge_New") ; o_Knowledge_New.multiple = true ; function f_listbox() { if ( v_Knowledge_New.indexOf(",") > 0 ) { for (var i=0 ; i < o_Knowledge_New.options.length; i++ ) { if(o_Knowledge_New[i].value == v_Knowledge_New) { o_Knowledge_New.remove(i); break ; } } var o_st = v_Knowledge_New.split(", ") ; for (var j=0 ; j < o_st.length; j++) { for (var i=0 ; i < o_Knowledge_New.options.length; i++ ) { if(o_st[j]== o_Knowledge_New.options[i].value){ o_Knowledge_New.options[i].selected = true ; break ; } } } } } window.onload = f_listbox ; function check_listbox() { var maximum_selections = 5; var MyListbox = document.getElementsByName("EditRecordKnowledge_New")[0]; var number_selections = 0; for (var i=0; i<MyListbox.length; i++) { if (MyListbox.options[i].selected) number_selections++; } if (number_selections>maximum_selections) { alert("You can select only " + maximum_selections + " items"); return false } } document.getElementById("caspioform").onsubmit=check_listbox; </SCRIPT> I've deleted a function, I think, it duplicates the functional and doesn't work in my account. Is it lost anything if this code is entered instead of the existed?
  10. Hi ccarls3, I've posted a script, I think, it can help: http://forums.caspio.com/index.php/topic/5341-validate-past-and-future-dates/ I'll be grateful, if you tell me if the code works. Have a nice day!
  11. Hi everyone, I'd like to share this code, that validates if the entered date is correct. Enter the name of your field instead of "myDate", enter the correct numbers for allowedDaysInPast and allowedDaysInFuture variables, enter texts of your messages. If you don't want to validate in past or in future you can delete the correspond block. Then add a Header@Footer element, select the Footer element, click the Source button and enter the code. <SCRIPT LANGUAGE="JavaScript"> function validate_dates() { var dateFieldName = "myDate"; var allowedDaysInPast = 1; var deniedMessagePast = "The entered date cannot be earlier than yesterday"; var allowedDaysInFuture = 1; var deniedMessageFuture = "The entered date cannot be later than tomorrow"; dateFieldName = "InsertRecord" + dateFieldName; var entered_value = document.getElementById(dateFieldName).value; var entered_date = new Date(entered_value); //Start of Validating in past var todayP = new Date(); var allowedDatePast = new Date(todayP.setDate(todayP.getDate() - allowedDaysInPast)); allowedDatePast = allowedDatePast.setHours(0,0,0,0); if(entered_date < allowedDatePast) { alert(deniedMessagePast); return false; } //Finish of validating in past //Start of Validating in future var todayF = new Date(); var allowedDateFuture = new Date(todayF.setDate(todayF.getDate() + allowedDaysInFuture)); allowedDateFuture = allowedDateFuture.setHours(23,59,59); if(entered_date > allowedDateFuture) { alert(deniedMessageFuture); return false; } //Finish of validating in future } document.getElementById("caspioform").onsubmit=validate_dates; </SCRIPT> I'll be grateful, if you tell me if the code works or if any errors occur. Have a nice day!
  12. Hi Peter, Welcome to the forum! I think, the following code should work: <SCRIPT LANGUAGE="JavaScript"> function calculate() { var fieldAmount = "amount"; var fieldRadioButton = "radiobutton"; var fieldOrder = "1"; fieldRadioButton = "InsertRecord" + fieldRadioButton + fieldOrder; fieldAmount = "InsertRecord" + fieldAmount ; if(document.getElementById(fieldRadioButton).checked) { var currentValue = parseFloat(document.getElementById(fieldAmount).value); if(currentValue>0) { currentValue = currentValue*(-1); document.getElementById(fieldAmount).value = currentValue; } } } document.getElementById("caspioform").onsubmit=calculate; </SCRIPT> Enter names of your fields instead of "amount" and "radiobutton". The "fieldOrder" is the order of the "Payment" option in the radiobutton, the first option is "0"; the second option is "1". I'll be grateful, if you tell me if the code works. Have a nice day!
  13. Hi Alan, Welcome to the forum! You can check the "Response Time" on the following page (click your site, and you'll see details): http://status.caspio.com/ Please try clearing the cache and another browser, if it works for you. Sometime after updates a browser starts working slowly.
  14. Hi Elena, How are you? How's the weather in your city? I think, the following code checks the number of selections: <SCRIPT LANGUAGE="JavaScript"> function check_listbox() { var maximum_selections = 5; var MyListbox = document.getElementsByName("EditRecordFieldName")[0]; var number_selections = 0; for (var i=0; i<MyListbox.length; i++) { if (MyListbox.options[i].selected) number_selections++; } if (number_selections>maximum_selections) { alert("You can select only " + maximum_selections + " items"); return false } } document.getElementById("caspioform").onsubmit=check_listbox; </SCRIPT> You can add it after your current code. Don't forget to change names FieldName to the names of your fields. I'll be grateful, if you tell me if the code works. Have a nice day!
  15. You're very welcome! Now I'm in Ukraine, we also have about 10 degrees and clear sky
  16. Hi AR, Welcome to the forum! How are you? How's the weather in your city? I have edited the code, I hope, it works: <SCRIPT LANGUAGE="JavaScript"> var fieldname1 = "Your_Field1"; var fieldname2 = "Your_Field2"; var fieldname3 = "Your_Field3"; fieldname1 = "InsertRecord" + fieldname1; fieldname2 = "InsertRecord" + fieldname2; fieldname3 = "InsertRecord" + fieldname3; document.getElementById(fieldname1).value = 0; document.getElementById(fieldname2).value = 0; document.getElementById(fieldname3).value = 0; function calculate() { var field1 = parseFloat(document.getElementById(fieldname1).value); var field2 = parseFloat(document.getElementById(fieldname2).value); var field3 = parseFloat(document.getElementById(fieldname3).value); var virtual = field1 + field2 + field3; var sum = 100 - virtual; document.getElementById("cbParamVirtual1").value=sum; } function check() { if(parseFloat(document.getElementById("cbParamVirtual1").value)!=0) { alert(" SUM SHOULD BE 100%"); return false; } } document.getElementById("caspioform").onchange=calculate; document.getElementById("caspioform").onsubmit=check; </SCRIPT> Don't forget to change names Your_Field1 to the names of your fields. I'll be grateful, if you tell me if the code works. Have a nice day!
  17. Hi Jan, I'm glad that my scripts helped! And I learned several new facts about Norway! Thank you!
  18. Hi again Jan, I have tried with the Norwegian localization, and I get "NaN" as well. That's surprise for me! I have rewritten the code as follows: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDate").value; var strDays = stringDate.slice(0, 2); var strMonths = stringDate.slice(3, 5); var strYears = stringDate.slice(6); var strDate = strMonths + "/" + strDays + "/" + strYears; var v_Date = new Date(Date.parse(strDate)); var v_year = parseInt(v_Date.getFullYear()); var v_month = parseInt(v_Date.getMonth()); var v_period = v_year * 100 + v_month + 1; v_period = parseInt(v_period); document.getElementById("InsertRecordPeriod").value=v_period; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> And then I realized, that the code should be shorter, like follows: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDate").value; var v_period = parseInt(stringDate.slice(6)) * 100 + parseInt(stringDate.slice(3, 5)); document.getElementById("InsertRecordPeriod").value=parseInt(v_period); } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> I'll be grateful, if you tell me if the code works. I hope they do! Have a nice day!
  19. Hi ychaudhry, How are you? How's the weather in your city? I rewrite your code a bit: <SCRIPT LANGUAGE="JavaScript"> function getWeekNumber() { var d = new Date(); var entered = document.getElementById("InsertRecordDeliveryDate").value; if (entered.length > 0) d = new Date(Date.parse(entered)); d.setHours(0,0,0); d.setDate(d.getDate()+4-(d.getDay()||7)); return Math.ceil((((d-new Date(d.getFullYear(),0,1))/8.64e7)+1)/7); } function calculate() { var today = new Date(); var entered = document.getElementById("InsertRecordDeliveryDate").value; if (entered.length > 0) today = new Date(Date.parse(entered)); var dd = today.getDate(); var mm = today.getMonth()+1; var yyyy = today.getFullYear(); var wk = getWeekNumber(); var qtr = 1; if (wk>52){qtr=1} else if(wk<=13){qtr=1} else if (wk<=26){qtr=2} else if (wk<=39){qtr=3} else {qtr=4} document.getElementById("InsertRecordDeliveryDate").value = mm+'/'+dd+'/'+yyyy; document.getElementById("InsertRecordYR").value = yyyy; document.getElementById("InsertRecordWK").value = wk; document.getElementById("InsertRecordQTR").value = qtr; } /* On submitting the webform, the function calculate is executed */ document.onload = calculate(); document.getElementById("InsertRecordDeliveryDate").onchange=calculate; </SCRIPT> Change the name of the field ("InsertRecordDeliveryDate") to the your name of the field in both cases. I'll be grateful, if you tell me if the code works. Have a nice day!
  20. Hi Jan, Add alerts to see, where the problems start <SCRIPT LANGUAGE="JavaScript"> function setDate() { alert("Start"); var stringDate = document.getElementById("InsertRecordDate").value; alert(stringDate); var v_Date = new Date(Date.parse(stringDate)); alert(v_Date); var v_year = parseInt(v_Date.getFullYear()); alert(v_year); var v_month = parseInt(v_Date.getMonth()) + 1; alert(v_month); var v_period = v_year * 100 + v_month; alert(v_period); v_period = parseInt(v_period); alert(v_period); document.getElementById("InsertRecordPeriod").value=v_period; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> In which alert the first "NaN" is displayed?
  21. Hi Jan, Can I see the URL of the page? You can send it in the message. Wow! I know more about Norway now And Happy Halloween!
  22. Hi Jan, I've found a mistake in my code. I hope, now everything is fixed: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDate").value; var v_Date = new Date(Date.parse(stringDate)); var v_year = parseInt(v_Date.getFullYear()); var v_month = parseInt(v_Date.getMonth()); var v_period = v_year * 100 + v_month + 1; v_period = parseInt(v_period); document.getElementById("InsertRecordPeriod").value=v_period; } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> I thought, it's colder in Norway on Halloween And if I understand correctly, the 10 degrees centigrade is rather cold and should be even warmer? Have a nice day!
  23. Hi Jan, I think, you can add this code to the Footer (do not forget clicking the Source button and changing FIELDNAME to the name of your field): <SCRIPT LANGUAGE="JavaScript"> var myDate = new Date(); myDate.setFullYear(myDate.getFullYear()+1); var myMonth = myDate.getMonth() + 1; if (myMonth<10) {myMonth = "0" + myMonth;} var myDay = myDate.getDate(); if (myDay<10) {myDay = "0" + myDay;} var myYear = myDate.getFullYear(); var result = myDay + "." + myMonth + "." + myYear; document.getElementById("InsertRecordFIELDNAME").value=result; </SCRIPT> When a DataPage opens, the current date in the "dd.mm.yyyy" format is entered to the field. I'll be grateful, if you tell me if the code works. Have a nice day!
  24. Hi Jan, How are you? How's the weather in your city? I've corrected your code a bit: <SCRIPT LANGUAGE="JavaScript"> function setDate() { var stringDate = document.getElementById("InsertRecordDate").value; var v_Date = new Date(Date.parse(stringDate)); v_year = v_Date.getFullYear(); v_month = v_Date.getMonth(); v_period = v_year * 100 + v_month + 1; document.getElementById("InsertRecordPeriod").value=Math.round(v_period); } document.getElementById("caspioform").onsubmit=setDate; </SCRIPT> getMonth returns the number of a month, started from 0, so I added "+1" to the correspond line. I'll be grateful, if you tell me if the code works. Have a nice day!
  25. Hi Alan, How are you? How's the weather in your city? I think, you can edit your Localization and add the following code to the message: <style> #Mod0EditRecord { display: none; } </style> Then the button is should be hidden, if the message is displayed. And the message should be displayed, if the message isn't displayed. I'll be grateful, if you tell me if the code works. Have a nice day!
×
×
  • Create New...