Thread: Onclick

    #1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    May 2013
    Posts
    21
    Rep Power
    0

    Onclick


    My code works fine with onchange from cfinput field but i need to press Enter key to see the alert message + the value.

    I now add the link /button to go to the next page.

    # 1: WORKED: <button id="a" onclick="toggleError(this)">Button A</button>

    # 2: NOT WORKED: <a id="myLink" title="Click to do something" href="test2.cfm" onclick="toggleError(this);">link text</a>
    what can i do ?


    <script type="text/javascript">
    function whatsUp() {
    document.medform.t_item.value)
    alert("OnChange occurred. Current field value: " + document.medform.t_item.value)
    }

    </script>

    <cfif isDefined("form.t_item")>
    <cfdump var="#form#"><br />
    </cfif>

    <cfform name="medform" action="#cgi.SCRIPT_NAME#">
    Item name: <cfinput autosuggest="cfc:cfc.gg.lookupArt({cfautosuggestvalue})" type="text" name="t_item" size="50" typeahead="yes" onChange="whatsUp()">



    </cfform>


    thanks
  2. #2
  3. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Oct 2013
    Posts
    22
    Rep Power
    0
    Originally Posted by knkt
    My code works fine with onchange from cfinput field but i need to press Enter key to see the alert message + the value. How can use the onlcik by click on (<a id="myLink" href="##" onclick="whatsUp();">link text</a>)and still see the alert message + the value just like onchange?

    <script type="text/javascript">
    function whatsUp() {
    document.medform.t_item.value)
    alert("OnChange occurred. Current field value: " + document.medform.t_item.value)
    }
    function show() {
    alert(document.medform.t_item.value)
    }
    </script>

    <cfif isDefined("form.t_item")>
    <cfdump var="#form#"><br />
    </cfif>

    <cfform name="medform" action="#cgi.SCRIPT_NAME#">
    Item name: <cfinput autosuggest="cfc:cfc.gg.lookupArt({cfautosuggestvalue})" type="text" name="t_item" size="50" typeahead="yes" onChange="whatsUp()">

    <a id="myLink" href="##" onclick="whatsUp();">link text</a>

    </cfform>


    thanks
    It looks like your are using some sort of Javascript template library. This code is not pure javascript code. However I think I can still understand the code.

    But your code
    Code:
    function whatsUp() {
    document.medform.t_item.value)
    alert("OnChange occurred. Current field value: " + document.medform.t_item.value)
    }
    this is incomplete codes. I assume that the second line is IF statement but I can say for sure without actual code.

    I will assume that it is IF statement, then you probably just need to remove that line to see the alert on link click.

    Code:
    function whatsUp() {
    alert("OnChange occurred. Current field value: " + document.medform.t_item.value); //you are also missing semicolon - although a browser will execute without it, it is not good coding practice 
    }

IMN logo majestic logo threadwatch logo seochat tools logo