Workflow Soluiton

 View Only
  • 1.  JavaScript Set Textbox to readonly/write

    Posted Nov 03, 2014 10:56 AM

    Hello,

    I am trying to use a javascript to set a textbox to write if the  SQL query returns null data and does not fill out the textbox.  I am having trouble incorporating this into workflow.  I added the script to the form and create an onload event to call the function. 

    I also tried adding the function to an event on the text box using onactivate, but it doesnt seem to work properly.  I set the text box to read only in workflow, then when the form loads and has no data in the field, i can write to it.  Once i click on the submit button all fields reset and error out saying field required.  Has anyone gotten this to work?

    function ReadOnly()
     
    {
     
    var text = document.getElementById("textbox").value;
     
    if (!text.match(/\S/))
     
    {
     
    document.getElementById("textbox").readOnly = false;
     
    }else
     
    {
     
    return true;
     
    }


  • 2.  RE: JavaScript Set Textbox to readonly/write
    Best Answer

    Posted Nov 03, 2014 11:12 AM
      |   view attached

    Which part doesn't work?  I created a quick test package that is using .disabled instead of .readOnly, let me know if it helps.

    Attached.

    The body onload event looks like this:

    var testbox = document.getElementById('TestTextBox');

    if (testbox.value == '') {
    testbox.disabled = true;
    }
    else {
    testbox.disabled = false;
    }

    Attachment(s)

    package
    TestWebForm.package   1.78 MB 1 version


  • 3.  RE: JavaScript Set Textbox to readonly/write

    Posted Nov 03, 2014 11:17 AM

    When it comes to javascript, there is nothing like adding windows alerts to test if your function is firing properly... just add a "window.alert('insert text here');" wherever necessary.

    window.alert('got here');

    window.alert('path 1');

    ...

    One thing you need to have in your example is to have the Control ID of your textbox to be "textbox"... make sure that is set.

    var text = document.getElementById("textbox").value;


  • 4.  RE: JavaScript Set Textbox to readonly/write

    Posted Nov 03, 2014 11:44 AM

    Sorry - I got the logic backwards from what you wanted.  Also, if you'd rather have readOnly, just swap out "readOnly" for "disabled" in my example.