• Resolved h4mm3r0g0d

    (@h4mm3r0g0d)


    I am trying to get a javascript funtion to work with a form. I have it working 100% fine if wordpress was normal html sites. I then copy and pasted the head side of my java into the Head section of the “Scripts” tab on the editor. I then paste the actual code of the form into the “Text” side of the webpage. I hit publish/update and view the page and the form is there. When I hit the button to calculate the form and display the reading it does nothing. Inspector on Google Chrome tells me there is a unexpected token even though I have ran through the code 1000 times to check. I have noticed that in source code I can’t see the script that should now be in the head. So I copied the script to the page before(and after on seperate times) and still get the same error and nothing working properly. Here is the link to the html version that works perfectly fine without problems Link to working HTML page

    Here is the script code that should be in head

    <script type="text/javascript">
    
    function Calculate() {
    A = document.frmOne.BAL.value
    B = document.frmOne.RISK.value
    C = document.frmOne.SL.value
    A = Number(A)
    B = Number(B)
    B = B/100
    C = Number(C)
    D = C + 1
    E = D + 1
    F = E + 1
    G = F + 1
    H = (A * B)/C
    H = Math.floor(H)/100
    I = (A * B)/D
    I = Math.floor(I)/100
    J = (A * B)/E
    J = Math.floor(J)/100
    K = (A * B)/F
    K = Math.floor(K)/100
    L = (A * B)/G
    L = Math.floor(L)/100
    document.frmOne.SL1.value = C
    document.frmOne.SL2.value = D
    document.frmOne.SL3.value = E
    document.frmOne.SL4.value = F
    document.frmOne.SL5.value = G
    document.frmOne.LS1.value = H
    document.frmOne.LS2.value = I
    document.frmOne.LS3.value = J
    document.frmOne.LS4.value = K
    document.frmOne.LS5.value = L
    }
    </SCRIPT>

    And here is the form data that should be working also but isn’t

    <FORM NAME = frmOne>
    <p>Balance $ <input type="text" name="BAL" id="BAL" />
    </p>
    <p>% at risk <input type="text" name="RISK" id="RISK" />
    </p>
    <p>Smallest SL <input type="text" name="SL" id="SL" />
    </p>
    <p>
      <Input Type = Button NAME = b1 VALUE = "Calculate" onClick = Calculate()>
    </p>
    <p><table id="output" width="100%">
    <tr>
    <td><input name = SL1 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = SL2 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = SL3 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = SL4 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = SL5 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    </tr>
    <td><input name = LS1 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = LS2 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = LS3 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = LS4 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    <td><input name = LS5 type = Text  value = "" size="5" readonly="readonly" />
    </td>
    </p>
    </FORM>

    Please help.
    -h4mm3r0g0d

Viewing 7 replies - 1 through 7 (of 7 total)
  • Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    Most importantly you need to link to a page with the issue

    Thread Starter h4mm3r0g0d

    (@h4mm3r0g0d)

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    lol enable right click

    Thread Starter h4mm3r0g0d

    (@h4mm3r0g0d)

    I am unable to turn that off on just one page. But you can still access the source code and the developer console through the tools menu of your browser.

    Thread Starter h4mm3r0g0d

    (@h4mm3r0g0d)

    I have enabled the right clicking for you. I have also changed the function name to something different in an attempt to make sure there wasn’t a conflict. What seems to be the problem here with declaring a function. This coding worked 100% fine when not in wordpress the instant it goes into wordpress it won’t work.

    -h4mm3r0g0d

    Andrew Nevins

    (@anevins)

    WCLDN 2018 Contributor | Volunteer support

    I then copy and pasted the head side of my java into the Head section of the “Scripts” tab on the editor.

    What is this scripts tab? Can you take a screenshot of this and link us to it?

    Thread Starter h4mm3r0g0d

    (@h4mm3r0g0d)

    No need to continue I fixed it my self by forcing the code to parse correctly. might want to fix the text editor on pages to use html correctly..

Viewing 7 replies - 1 through 7 (of 7 total)

The topic ‘WordPress and javascript funtions’ is closed to new replies.