简体   繁体   中英

JQuery Not Triggering On Button.click

I've written some code that should check a textbox (ID tfa_1) to see if its empty or contains text, this should trigger on a next page button (wfpagenextID6) being clicked.

I've tried replacing my script with an alert("test.") and it dosent appear, so im assuming I have my trigger wrong but I cannot work out what I have done wrong!

My HTML that defines the textbox is below:

<input type="text" id="tfa_2685" name="tfa_2685" value="" placeholder="" title="Previous Surname (if applicable) " class="">

and the button is

<input value="Next Page" type="button" class="wfPageNextButton" wfpageindex_activate="7" id="wfPageNextId6" style="visibility: visible;">

Both of these are generated and I cannot change them!

My Script is:

<script>
$(document).ready(function(){ 
$('#wfPageNextId6').click(function(){
 var inp.Val= $("#tfa_2685").val();
  if (inp.val().length > 0) {
    alert("Test.");
    }
    });
    })
</script>

if you want to assign value to inp variable, you should just do: var inp = $("#tfa_2685").val(); And then call to inp.val() just replace with inp , for inp is not jQuery object so it doesn't have val() method

An identifier ( variable ) must not contains dots. ( see more details ECMAScript specification in section 7.6 Identifier Names and Identifiers )

the next variable declaration is wrong

var inp.Val= $("#tfa_2685").val();

to fix this

 var inp = $("#tfa_2685");

You have syntax, try this:

$(document).ready(function(){ 
$('#wfPageNextId6').click(function(){
 var inpVal= $("#tfa_2685").val();
  if (inpVal.length > 0) {
    alert("Test.");
    }
    });
});

https://jsfiddle.net/cua40s80/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM